zackiles / bluebird-queue Goto Github PK
View Code? Open in Web Editor NEWCreate promise queues with Bluebird promises. Add concurrency and delays.
Create promise queues with Bluebird promises. Add concurrency and delays.
Hi it will be nice if there is an option to add items at the begging of the queue. If you dont have the time and think its a good idea I can do a pull request.
bluebird-queue in npm isn't updated. Method addNowInfront is missing.
I am using a bluebird-queue via NodeJS to queue HTTP endpoints as tasks. Each task has a 3-level Promise dependancy that has to resolve before it is complete.
One Task
GET -> endpoint 1 // returns promise
GET -> other endpoints in async // returns promise
POST -> final endpoint // return promise
I put 20,000 of these tasks into the bluebird-queue with queue.add() and then subsequently call queue.start(). All errors are caught and the handlers resolve the Promise so the task can complete.
I have set concurrency to 50. My initial expectation is that the queue will process 50 at any given time but instead it waits for the first 50 to complete before starting on the next 50.
Unfortunately, some of these Requests can take up to 10 secs to complete - and if a single request takes longer to finish, the whole queue stalls until the Promise resolves.
I have tested with promise-queue
and it differs from bluebird-queue
where the former processes tasks in the queue at max of 50 tasks at any given time instead of per 50 at a time.
Is this intended behaviour?
Here are my config settings:
var Queue = require('bluebird-queue'),
queue = new Queue({
concurrency: 50,
delay: 10, // ms
interval: 1 // ms not quite sure what this means
});
For your reference, here is the link to the stackoverflow question.
Hi, doesn't the following code overwrites any custom onComplete and onError handlers passed to queue's constructor?
return new BlueBird(function(resolve, reject) {
self.onComplete = resolve;
self.onError = reject;
});
I have a code which makes api call for list of items to fetch data of , then it pulls data of each item. Let's say it looks like following:
var Queue = require('bluebird-queue');
api.getContainer(contaierId)
.then(function (items) {
var itemQueue = new Queue({
concurrency: 1,
delay: 2000
});
itemQueue.add(items.map(function (item) {
return api.getItemDetails(item); // returns promise
}))
return itemQueue.start();
})
.then(function (itemDetails) {
...
});
getContainer
and getItemDetails
are functions which return Promise
, which return request
.
After I start the queue, first getItemDetails
is called properly after a delay
, but then it invokes everything else and waits for the remaining time.
bluebird: v3.4.5
bluebird-queue: v0.0.8
node: v4.4.7
Edit: Posted more accurate example.
On line 86 of index.js
, the if(typeof func === 'array') {
check will never be true, since typeof [] === "object"
. It should be if(func instanceof Array) {
instead.
Hi, thank you for your great lib. I have a question though: what happen when I run start() and after onComplete/result promise is fired I add another task? Will it be processed or not?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.