Support all ^TaskLike in do! and let! similar to F#'s task, this includes non-generic Task and ValueTask with do!
#109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #43.
Fixes #110.
This basically allows:
On top of that, this PR will add support for all of
^TaskLikethat F#'staskalso supports. This change is necessary, as the above distinction isn't possible by adding an overload for the non-genericTaskandValueTask, for the simple reason thatTask<'T> :> Task.The solution chosen in F# was to have a
Bindimplementation that takes an SRTP parameter of^TaskLike, which has aGetAwaiter() -> 'T when 'T :> ICriticalNotifyCompletion, as follows:Because
Task<'T>does have aGetAwaiteron the type, but also inheritsTaskwhich in turn implements the non-genericTaskAwaiter, a conflict arises causing an "ambiguous overload" error with just the code above. To solve this, a high-priority overloadBindforTask<'T>is added, which specifically pick theTask<'T>.GetAwaiter: unit -> TaskAwaiter<'T>, as opposed to(Task<'T> :> Task).GetAwaiter: unit -> unit.Note that the non-generic
Taskonly has the non-genericGetResult: unit -> unit, which fits the above signature where'TResult1becomesunit, and no ambiguity arises.In other words,
TaskLikeare:ValueTask,ValueTask<'T>,Task. NotTaskLikeper the above definition isTask<'T>, which has its own overload.