We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
ValueTask.ignore
1 parent b291d2a commit 5f1f9e4Copy full SHA for 5f1f9e4
1 file changed
src/FSharp.Control.TaskSeq/Utils.fs
@@ -33,7 +33,11 @@ module ValueTask =
33
34
/// Ignore a ValueTask<'T>, returns a non-generic ValueTask.
35
let inline ignore (vtask: ValueTask<'T>) =
36
- if vtask.IsCompleted then
+ // this implementation follows Stephen Toub's advice, see:
37
+ // https://github.com/dotnet/runtime/issues/31503#issuecomment-554415966
38
+ if vtask.IsCompletedSuccessfully then
39
+ // ensure any side effect executes
40
+ vtask.Result |> ignore
41
ValueTask()
42
else
43
ValueTask(vtask.AsTask())
@@ -63,6 +67,7 @@ module Task =
63
67
/// Convert a Task<'T> into a non-generic Task, ignoring the result
64
68
let inline ignore (task: Task<'T>) =
65
69
TaskBuilder.task {
70
+ // ensure the task is awaited
66
71
let! _ = task
72
return ()
73
}
0 commit comments