Skip to content

ParallelCollectors.parallelForEach()#1223

Draft
pivovarit wants to merge 1 commit intomainfrom
parallel-for-each
Draft

ParallelCollectors.parallelForEach()#1223
pivovarit wants to merge 1 commit intomainfrom
parallel-for-each

Conversation

@pivovarit
Copy link
Copy Markdown
Owner

@pivovarit pivovarit commented Mar 7, 2026

Adds ParallelCollectors.parallelForEach() - a fire-and-forget collector for parallel side-effecting operations that returns CompletableFuture<Void> instead of collecting results.

This fills a gap in the API for common use cases like sending notifications, writing to external systems, or updating caches in parallel - where callers care about completion but not about return values.

Three overloads following established conventions:

// Default - Virtual Threads, unbounded parallelism
stream.collect(parallelForEach(i -> sendNotification(i)));

// Configurable - custom executor, parallelism, batching, decorators
stream.collect(parallelForEach(i -> sendNotification(i), c -> c
    .executor(executor)
    .parallelism(64)
    .batching()
));

// Convenience - just a parallelism cap
stream.collect(parallelForEach(i -> sendNotification(i), 64));

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 7, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant