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

interval & intervalCap question #46

Closed
AlvMF1 opened this issue Oct 2, 2018 · 5 comments
Closed

interval & intervalCap question #46

AlvMF1 opened this issue Oct 2, 2018 · 5 comments

Comments

@AlvMF1
Copy link

AlvMF1 commented Oct 2, 2018

Hey everyone!

Here's what I'm trying to accomplish. Please let me know if that's possible with this cool lib:

I need a queue to run 5 concurrent tasks. Let's say I add 10. I'd like to see 5 tasks running, a delay, another 5.

Is it possible to do it with interval and/or intervalCap? I couldn't figure it out just by reading the readme.

Thanks!

@sindresorhus
Copy link
Owner

// @Rafael09ED

@szmarczak
Copy link
Collaborator

What are you trying to achieve? 5 tasks then delay (delay starts when all the tasks are completed) or these 5 tasks must be completed in a given time?

@AlvMF1
Copy link
Author

AlvMF1 commented Oct 3, 2018

added 4 tasks
starting 2 tasks...
task 1 finished
task 2 finished
waiting 5 secs...
starting 2 tasks...
task 3 finished
task 4 finished
all done!

😄

@Rafael09ED
Copy link
Contributor

If you wanted to run at max 2 tasks every 5 seconds you can use interval = 5000 and intervalCap = 2 however I don't think that's what you are looking for. The output for the second example you gave would then be:

added 4 tasks
starting 2 tasks...
start of waiting 5 secs...
task 1 finished
task 2 finished

end of waiting 5 secs... (next two tasks may run now) (this can also happen before task 1 or 2 ends)
starting 2 tasks...
task 3 finished
task 4 finished
all done!

For the exact behavior you have described where it waits five seconds after all have finished, I would look into using the .onIdle() promise or Promise.all() with a timeout for 5 seconds that then adds the next set of promises you want to run.

@AlvMF1
Copy link
Author

AlvMF1 commented Oct 3, 2018

Ok. I know Promise.all() is a possibility. Just wanted to make sure if it could be done with the queue itself.
Thanks anyways!

@AlvMF1 AlvMF1 closed this as completed Oct 3, 2018
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

No branches or pull requests

4 participants