File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
src/FSharpPlus/Extensions Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -226,12 +226,20 @@ module ValueTask =
226226
227227 /// <summary>Creates a ValueTask that ignores the result of the source ValueTask.</summary>
228228 /// <remarks>It can be used to convert non-generic ValueTask to unit ValueTask.</remarks>
229- let ignore ( source : ValueTask < 'T >) =
230- if source.IsCompletedSuccessfully then
231- source.GetAwaiter() .GetResult() |> ignore
232- Unchecked.defaultof<_>
229+ let ignore ( source : ValueTask ) : ValueTask < unit > =
230+ if source.IsCompletedSuccessfully then Unchecked.defaultof<_>
233231 else
234- new ValueTask ( source.AsTask ())
232+ let tcs = TaskCompletionSource< unit> ()
233+ if source.IsFaulted then tcs.SetException ( Unchecked.nonNull ( source.AsTask() .Exception)) .InnerExceptions
234+ elif source.IsCanceled then tcs.SetCanceled ()
235+ else
236+ let k ( t : ValueTask ) : unit =
237+ if t.IsCanceled then tcs.SetCanceled ()
238+ elif t.IsFaulted then tcs.SetException ( Unchecked.nonNull ( source.AsTask() .Exception)) .InnerExceptions
239+ else tcs.SetResult ()
240+ if source.IsCompleted then k source
241+ else source.ConfigureAwait( false ) .GetAwaiter() .UnsafeOnCompleted ( fun () -> k source)
242+ tcs.Task |> ValueTask< unit>
235243
236244
237245 /// Raises an exception in the ValueTask
You can’t perform that action at this time.
0 commit comments