Skip to content

Provide an Async conversion function for structural awaiters #559

@baronfel

Description

@baronfel

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:

  • This is not a question (e.g. like one you might ask on StackOverflow) and I have searched StackOverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I would be willing to help implement and/or test this
  • I or my company would be willing to help crowdfund F# Software Foundation members to work on this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions