I propose we provide functions on the Async module that provide conversions to Async<T> for so-called structural awaiters, meaning types that have a member GetAwaiter: unit -> #awaiter<T>, where #awaiter is a flexible type representing the following constraints:
- implements one of
INotifyCompletion or ICriticalNotifyCompletion,
- has a boolean property getter
IsCompleted, and
- has a member
GetResult () -> T, where T can be void
This will help with interop situations where C# library developers have rolled custom awaiters instead of using Task and Task<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:
I propose we provide functions on the
Asyncmodule that provide conversions toAsync<T>for so-calledstructural awaiters, meaning types that have a memberGetAwaiter: unit -> #awaiter<T>, where#awaiteris a flexible type representing the following constraints:INotifyCompletionorICriticalNotifyCompletion,IsCompleted, andGetResult () -> T, whereTcan bevoidThis will help with interop situations where C# library developers have rolled custom awaiters instead of using
TaskandTask<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: