@@ -5,37 +5,14 @@ namespace FSharpPlus
5
5
/// Additional operations on ValueTask<'T>
6
6
[<RequireQualifiedAccess>]
7
7
module ValueTask =
8
-
9
- open System.Threading
8
+
10
9
open System.Threading .Tasks
11
10
12
11
let inline internal (| Succeeded | Canceled | Faulted |) ( t : ValueTask < 'T >) =
13
12
if t.IsCompletedSuccessfully then Succeeded t.Result
14
13
elif t.IsCanceled then Canceled
15
- else Faulted ( t.AsTask() .Exception.InnerExceptions)
16
-
17
- /// <summary>Creates a <see cref="ValueTask{TResult}"/> that's completed successfully with the specified result.</summary>
18
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
19
- /// <param name="result">The result to store into the completed task.</param>
20
- /// <returns>The successfully completed task.</returns>
21
- let FromResult < 'TResult > ( result : 'TResult ) = ValueTask< 'TResult> result
22
-
23
- /// <summary>Creates a <see cref="ValueTask{TResult}"/> that's completed exceptionally with the specified exception.</summary>
24
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
25
- /// <param name="exception">The exception with which to complete the task.</param>
26
- /// <returns>The faulted task.</returns>
27
- let FromException < 'TResult > ( ``exception`` : exn ) = ValueTask< 'TResult> ( Task.FromException< 'TResult> `` exception `` )
14
+ else Faulted ( t.AsTask() .Exception.InnerExceptions)
28
15
29
- /// <summary>Creates a <see cref="ValueTask{TResult}"/> that's completed due to cancellation with the specified token.</summary>
30
- /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
31
- /// <param name="cancellationToken">The token with which to complete the task.</param>
32
- /// <returns>The canceled task.</returns>
33
- let FromCanceled < 'TResult > ( cancellationToken : CancellationToken ) = ValueTask< 'TResult> ( Task.FromCanceled< 'TResult> cancellationToken)
34
-
35
- /// <summary>Creates a <see cref="ValueTask{TResult}"/> from a <see cref="Task{TResult}"/>.</summary>
36
- /// <param name="source">Task workflow.</param>
37
- let FromTask < 'TResult > ( source : Task < 'TResult >) = ValueTask< 'TResult> source
38
-
39
16
let inline internal continueTask ( tcs : TaskCompletionSource < 'Result >) ( x : ValueTask < 't >) ( k : 't -> unit ) =
40
17
let f = function
41
18
| Succeeded r -> k r
@@ -47,6 +24,8 @@ module ValueTask =
47
24
aw.OnCompleted ( fun () -> f x)
48
25
49
26
/// <summary>Creates a ValueTask workflow from 'source' another, mapping its result with 'f'.</summary>
27
+ /// <param name="f">The mapping function.</param>
28
+ /// <param name="source">ValueTask workflow.</param>
50
29
let map ( f : 'T -> 'U ) ( source : ValueTask < 'T >) : ValueTask < 'U > =
51
30
let tcs = TaskCompletionSource< 'U> ()
52
31
continueTask tcs source ( fun x ->
@@ -133,6 +112,6 @@ module ValueTask =
133
112
134
113
135
114
/// Raises an exception in the ValueTask
136
- let raise ( e : exn ) = FromException e
115
+ let raise ( ``exception`` : exn ) = ValueTask < 'TResult > ( Task. FromException< 'TResult > `` exception `` )
137
116
138
117
#endif
0 commit comments