@@ -152,16 +152,36 @@ public static Task<Option<T>> SomeAsync(T value) =>
152
152
/// Creates a new <see cref="Option{T}"/> with the value of the awaited Task.
153
153
/// </summary>
154
154
/// <param name="value"></param>
155
+ /// <param name="cancellationToken"></param>
155
156
/// <returns></returns>
156
- public static async Task < Option < T > > SomeAsync ( Task < T > value ) =>
157
- Some ( await value ) ;
157
+ public static async Task < Option < T > > SomeAsync (
158
+ Task < T > value ,
159
+ CancellationToken ? cancellationToken = null )
160
+ {
161
+ var result = await value . WaitOrCancel ( cancellationToken ) ;
162
+ return Some ( result ) ;
163
+ }
164
+
165
+ /// <summary>
166
+ /// An Option of <see cref="Option{T}"/> with no value.
167
+ /// </summary>
168
+ /// <returns></returns>
169
+ public static Option < T > NoneValue =>
170
+ new ( ) ;
158
171
159
172
/// <summary>
160
173
/// Creates a new <see cref="Option{T}"/> with no value.
161
174
/// </summary>
162
175
/// <returns></returns>
163
176
public static Option < T > None ( ) =>
164
- new ( ) ;
177
+ NoneValue ;
178
+
179
+ /// <summary>
180
+ /// An Option of <see cref="Option{T}"/> with no value wrapped in a completed Task.
181
+ /// </summary>
182
+ /// <returns></returns>
183
+ public static Task < Option < T > > NoneValueAsync =>
184
+ Task . FromResult ( None ( ) ) ;
165
185
166
186
/// <summary>
167
187
/// Creates a new <see cref="Option{T}"/> with no value wrapped in a completed Task.
@@ -280,7 +300,13 @@ public static Task<Option<T>> SomeAsync<T>(T value) =>
280
300
/// Creates a new <see cref="Option{T}"/> with the value of the awaited Task.
281
301
/// </summary>
282
302
/// <param name="value"></param>
303
+ /// <param name="cancellationToken"></param>
283
304
/// <returns></returns>
284
- public static async Task < Option < T > > SomeAsync < T > ( Task < T > value ) =>
285
- Option < T > . Some ( await value ) ;
305
+ public static async Task < Option < T > > SomeAsync < T > (
306
+ Task < T > value ,
307
+ CancellationToken ? cancellationToken = null )
308
+ {
309
+ var result = await value . WaitOrCancel ( cancellationToken ) ;
310
+ return Option < T > . Some ( result ) ;
311
+ }
286
312
}
0 commit comments