Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Add Parallel.InvokeAsync #112900

Open
bill-poole opened this issue Feb 25, 2025 · 1 comment
Open

[API Proposal]: Add Parallel.InvokeAsync #112900

bill-poole opened this issue Feb 25, 2025 · 1 comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading.Tasks untriaged New issue has not been triaged by the area owner

Comments

@bill-poole
Copy link

bill-poole commented Feb 25, 2025

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

@bill-poole bill-poole added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Feb 25, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 25, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-threading-tasks
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading.Tasks untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

1 participant