- Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Threading.Tasks
Milestone
Description
Background and motivation
Parallel.Invoke currently provides for concurrently executing a set of Actions, but does not provide for executing a set of async actions (Func<CancellationToken, ValueTask>). I have found a frequent need to concurrently execute a set of async actions, where if any action fails, all other actions are cancelled and the exception of the failing action is thrown. i.e., similar behavior is required that is provided by Parallel.ForEachAsync, but where ForEachAsync executes a single function for a collection of inputs, Parallel.InvokeAsync would execute a collection of async actions.
API Proposal
namespace System.Threading.Tasks public static class Parallel { public static Task InvokeAsync(params Func<CancellationToken, ValueTask>[] actions); public static Task InvokeAsync(CancellationToken cancellationToken, params Func<CancellationToken, ValueTask>[] actions); public static Task InvokeAsync(ParallelOptions parallelOptions, params Func<CancellationToken, ValueTask> actions); }API Usage
await Parallel.InvokeAsync( async ct => obj.Id = new(obj.Id.ExternalId, internalId: await idMapper.GetInternalId(obj.Id.ExternalId, ct)), async ct => obj.ParentId = new(obj.Id.ExternalId, internalId: await idMapper.GetInternalId(obj.ParentId.ExternalId, ct)), async ct => obj.OrderId = new(obj.Id.ExternalId, internalId: await idMapper.GetInternalId(obj.OrderId.ExternalId, ct)), async ct => obj.AssignmentId = new(obj.Id.ExternalId, internalId: await idMapper.GetInternalId(obj.AssignmentId.ExternalId, ct)));Alternative Designs
No response
Risks
No response
FedeArre
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Threading.Tasks