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