@@ -1021,6 +1021,39 @@ public static Guid NewGuid()
1021
1021
/// </remarks>
1022
1022
public static bool Patched ( string patchId ) => Context . Patch ( patchId , deprecated : false ) ;
1023
1023
1024
+ /// <summary>
1025
+ /// Workflow-safe form of <see cref="Task.Run(Func{Task}, CancellationToken)" />.
1026
+ /// </summary>
1027
+ /// <param name="function">The work to execute asynchronously.</param>
1028
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work
1029
+ /// if it has not yet started. Defaults to <see cref="CancellationToken"/>.</param>
1030
+ /// <returns>A task for the running task (but not necessarily the task that is returned
1031
+ /// from the function).</returns>
1032
+ public static Task RunTaskAsync (
1033
+ Func < Task > function , CancellationToken ? cancellationToken = null ) =>
1034
+ Task . Factory . StartNew (
1035
+ function ,
1036
+ cancellationToken ?? CancellationToken ,
1037
+ TaskCreationOptions . None ,
1038
+ TaskScheduler . Current ) . Unwrap ( ) ;
1039
+
1040
+ /// <summary>
1041
+ /// Workflow-safe form of <see cref="Task.Run{TResult}(Func{TResult}, CancellationToken)" />.
1042
+ /// </summary>
1043
+ /// <typeparam name="TResult">The type of the result returned by the task.</typeparam>
1044
+ /// <param name="function">The work to execute asynchronously.</param>
1045
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work
1046
+ /// if it has not yet started. Defaults to <see cref="CancellationToken"/>.</param>
1047
+ /// <returns>A task for the running task (but not necessarily the task that is returned
1048
+ /// from the function).</returns>
1049
+ public static Task < TResult > RunTaskAsync < TResult > (
1050
+ Func < Task < TResult > > function , CancellationToken ? cancellationToken = null ) =>
1051
+ Task . Factory . StartNew (
1052
+ function ,
1053
+ cancellationToken ?? CancellationToken ,
1054
+ TaskCreationOptions . None ,
1055
+ TaskScheduler . Current ) . Unwrap ( ) ;
1056
+
1024
1057
/// <summary>
1025
1058
/// Start a child workflow via lambda invoking the run method.
1026
1059
/// </summary>
@@ -1220,6 +1253,44 @@ public static async Task<Task<TResult>> WhenAnyAsync<TResult>(IEnumerable<Task<T
1220
1253
return ( Task < TResult > ) task ;
1221
1254
}
1222
1255
1256
+ /// <summary>
1257
+ /// Workflow-safe form of <see cref="Task.WhenAll(IEnumerable{Task})" /> (which just calls
1258
+ /// the standard library call currently because it is already safe).
1259
+ /// </summary>
1260
+ /// <param name="tasks">The tasks to wait on for completion.</param>
1261
+ /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
1262
+ public static Task WhenAllAsync ( IEnumerable < Task > tasks ) =>
1263
+ Task . WhenAll ( tasks ) ;
1264
+
1265
+ /// <summary>
1266
+ /// Workflow-safe form of <see cref="Task.WhenAll(Task[])" /> (which just calls the standard
1267
+ /// library call currently because it is already safe).
1268
+ /// </summary>
1269
+ /// <param name="tasks">The tasks to wait on for completion.</param>
1270
+ /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
1271
+ public static Task WhenAllAsync ( params Task [ ] tasks ) =>
1272
+ Task . WhenAll ( tasks ) ;
1273
+
1274
+ /// <summary>
1275
+ /// Workflow-safe form of <see cref="Task.WhenAll{TResult}(IEnumerable{Task{TResult}})" />
1276
+ /// (which just calls the standard library call currently because it is already safe).
1277
+ /// </summary>
1278
+ /// <typeparam name="TResult">The type of the completed task..</typeparam>
1279
+ /// <param name="tasks">The tasks to wait on for completion.</param>
1280
+ /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
1281
+ public static Task < TResult [ ] > WhenAllAsync < TResult > ( IEnumerable < Task < TResult > > tasks ) =>
1282
+ Task . WhenAll ( tasks ) ;
1283
+
1284
+ /// <summary>
1285
+ /// Workflow-safe form of <see cref="Task.WhenAll{TResult}(Task{TResult}[])" /> (which just
1286
+ /// calls the standard library call currently because it is already safe).
1287
+ /// </summary>
1288
+ /// <typeparam name="TResult">The type of the completed task..</typeparam>
1289
+ /// <param name="tasks">The tasks to wait on for completion.</param>
1290
+ /// <returns>A task that represents the completion of all of the supplied tasks.</returns>
1291
+ public static Task < TResult [ ] > WhenAllAsync < TResult > ( params Task < TResult > [ ] tasks ) =>
1292
+ Task . WhenAll ( tasks ) ;
1293
+
1223
1294
/// <summary>
1224
1295
/// Unsafe calls that can be made in a workflow.
1225
1296
/// </summary>
0 commit comments