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

Method: limit #1

Open
yoshuawuyts opened this issue Mar 14, 2020 · 1 comment
Open

Method: limit #1

yoshuawuyts opened this issue Mar 14, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@yoshuawuyts
Copy link
Collaborator

It should be possible to limit the max concurrency. This likely needs to be built into the ParallelStream trait itself, with each impl being responsible for carrying it.

The default limit should be unlimited, with the executor and runtime scheduling resources.

API Outline

trait ParallelStream {
    fn limit(self, limit: impl Into<Option<usize>>) -> Self;
}

Usage

// Set max limit to 5
let out: Vec<usize> = parallel_stream::repeat(5)
    .take(100)
    .limit(5) // <-- set max concurrency
    .map(async |n| n * n)
    .collect()
    .await;

// Remove max limit
let out: Vec<usize> = parallel_stream::repeat(5)
    .take(100)
    .limit(None) // <-- set max concurrency
    .map(async |n| n * n)
    .collect()
    .await;

Naming

The name limit is inspired by the parameter name of for_each_concurrent. It seems small and to the point, though not particularly attached if there's something different that's concise yet to the point.

@yoshuawuyts yoshuawuyts mentioned this issue Mar 14, 2020
@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Mar 14, 2020
@ccope
Copy link

ccope commented Apr 23, 2021

It would be nice if you could specify a number of requests within a time period as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants