File tree Expand file tree Collapse file tree
src/FSharpPlus/Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -396,6 +396,16 @@ module Task =
396396 | Canceled -> tcs.SetCanceled ()
397397 source.ConfigureAwait( false ) .GetAwaiter() .UnsafeOnCompleted ( fun () -> k source)
398398 tcs.Task
399+
400+ /// Creates a Task from a Result value.
401+ /// If the Result is Ok, the Task will complete successfully with the value.
402+ /// If the Result is Error, the Task will complete unsuccessfully with the exception.
403+ /// <param name =" source " >The source Result.</param >
404+ /// <returns >The resulting Task.</returns >
405+ let ofResult ( source : Result < 'T , exn >) : Task < 'T > =
406+ match source with
407+ | Ok x -> Task.FromResult x
408+ | Error exn -> Task.FromException< 'T> exn
399409
400410 /// <summary >Creates a Task that's completed unsuccessfully with the specified exception.</summary >
401411 /// <param name =" exn " >The exception to be raised.</param >
Original file line number Diff line number Diff line change @@ -364,6 +364,16 @@ module ValueTask =
364364 source.ConfigureAwait( false ) .GetAwaiter() .UnsafeOnCompleted ( fun () -> k source)
365365 ValueTask< 'T> tcs.Task
366366
367+ /// Creates a Task from a Result value.
368+ /// If the Result is Ok, the Task will complete successfully with the value.
369+ /// If the Result is Error, the Task will complete unsuccessfully with the exception.
370+ /// <param name =" source " >The source Result.</param >
371+ /// <returns >The resulting Task.</returns >
372+ let ofResult ( source : Result < 'T , exn >) : ValueTask < 'T > =
373+ match source with
374+ | Ok x -> ValueTask.FromResult x
375+ | Error exn -> ValueTask.FromException< 'T> exn
376+
367377 /// <summary >Creates a ValueTask that's completed unsuccessfully with the specified exception.</summary >
368378 /// <param name =" exn " >The exception to be raised.</param >
369379 /// <returns >A ValueTask that is completed unsuccessfully with the specified exception.</returns >
You can’t perform that action at this time.
0 commit comments