Giter Site home page Giter Site logo

Add task to empty queue about cwait HOT 4 CLOSED

paglias avatar paglias commented on August 13, 2024
Add task to empty queue

from cwait.

Comments (4)

jjrv avatar jjrv commented on August 13, 2024

Yes you can always add a new task to the queue, and it starts immediately if the queue is empty or otherwise gets scheduled for later. A wrapped function should be completely transparent - you won't notice any difference in how it works other than the possible delay.

from cwait.

jjrv avatar jjrv commented on August 13, 2024

To clarify, wrapping a function doesn't alter the queue or the function in any way. It only creates a new closure referencing the queue and the function. You can wrap any function with any queue at any time and any number of times you need.

Closing this, but I can reopen if you have anything to add.

from cwait.

paglias avatar paglias commented on August 13, 2024

@jjrv thanks, what I meant is this: in the README example you have

var queue = new TaskQueue(Promise, 3);

Promise.map(list, queue.wrap(download))); // Download 3 files at a time.

now Promise.map returns a Promise, my understanding if a then callback is attached to the Promise object it can only be called once, so what happens in this case

var queue = new TaskQueue(Promise, 3);

Promise.map(list, queue.wrap(download)))
  .then(function () { console.log('done') });

// In 10 seconds all the items in the queue are processed and `done` is logged by the console

// 5 seconds after the processing ends a new Task is pushed to the queue
setTimeout(function () {
    queue.add(...);
}, 15000);

// Will the `then` callback be called once again after the newly added task has been processed?

from cwait.

jjrv avatar jjrv commented on August 13, 2024

No, "done" is not printed a second time. After the first time it's printed, no references to that function remain and it may be garbage collected.

from cwait.

Related Issues (9)

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.