Comments (4)
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.
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.
@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.
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)
- Does not appear to work with vanilla Promises HOT 1
- Queue doesn't process in order? HOT 1
- Just for historical interest: sendValue HOT 2
- Using with vanilla Promises HOT 2
- What if the `download` function is somehow async recursive? HOT 3
- Usage with vanilla Promise.all HOT 2
- Change concurrency level after initialization HOT 1
- Better typing for TaskQueue.wrap() HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cwait.