-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an Async conversion function for structural awaiters
#559
Comments
structural awaiters
structural awaiters
@baronfel I'd be interested to see a complete proposal and proto implementation for this, with examples of use - the linked example looks a bit thin to get the full idea and practical utility |
See also https://github.com/dustinmoris/Giraffe/blob/master/src/Giraffe/Tasks.fs#L266 for a guide for how to do this for the |
The task computation expression has moved, and it has a very nice generic binder here: https://github.com/rspeele/TaskBuilder.fs/blob/master/TaskBuilder.fs#L80 This binder seems to replicate the targeting criteria I was mentioning in the submission, and might be worth trying to replicate on async directly (via propagating the continuations) |
One thing I discovered was that there is no requirement for custom C# awaitables to block in their GetResult implementation. It's not expected in general (unless you know something special about a specific type like To achieve actual blocking until complete awaitables over than TaskAwaiter, something like this is needed (sorry for the C#): var awaiter = awaitable.GetAwaiter();
if (!awaiter.IsCompleted)
{
using (var completed = new ManualResetEventSlim())
{
awaiter.OnCompleted(completed.Set);
completed.Wait();
}
}
var result = awaiter.GetResult(); |
Note this functionality is available for |
I'm thinking we should have a general overloaded |
For posterity, this was closed as ‘completed’, and yes, it exists to some extend in |
I propose we provide functions on the
Async
module that provide conversions toAsync<T>
for so-calledstructural awaiters
, meaning types that have a memberGetAwaiter: unit -> #awaiter<T>
, where#awaiter
is a flexible type representing the following constraints:INotifyCompletion
orICriticalNotifyCompletion
,IsCompleted
, andGetResult () -> T
, whereT
can bevoid
This will help with interop situations where C# library developers have rolled custom awaiters instead of using
Task
andTask<T>
derivatives, for example in the Microsoft Bot Framework.There is a snippet at stackoverflow, but proper code review/hardening would be nice.
Pros and Cons
The advantages of making this adjustment to F# are easier more natural library interop.
The disadvantages of making this adjustment to F# are having to either hand-roll such a function, which may be easy to mess up considering SynchronizationContexts, etc, or accept blocking on GetResult.
Extra informtion
Estimated cost (XS, S, M, L, XL, XXL): S
Affidavit (must be submitted)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: