Git Product home page Git Product logo

Comments (5)

sindresorhus avatar sindresorhus commented on May 18, 2024

// @Rafael09ED

from p-queue.

szmarczak avatar szmarczak commented on May 18, 2024

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?

from p-queue.

AlvMF1 avatar AlvMF1 commented on May 18, 2024

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!

😄

from p-queue.

Rafael09ED avatar Rafael09ED commented on May 18, 2024

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.

from p-queue.

AlvMF1 avatar AlvMF1 commented on May 18, 2024

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

from p-queue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.