promise-queue / Promise Queue
Licence: mit
Promise-based queue
Stars: ✭ 210
Programming Languages
javascript
184084 projects - #8 most used programming language
Projects that are alternatives of or similar to Promise Queue
Wx Promise Request
解决微信小程序 wx.request 请求的并发数限制、不支持异步问题
Stars: ✭ 226 (+7.62%)
Mutual labels: promise, queue
Task Easy
A simple, customizable, and lightweight priority queue for promises.
Stars: ✭ 244 (+16.19%)
Mutual labels: promise, queue
easy-promise-queue
An easy JavaScript Promise queue which is automatically executed, concurrency controlled and suspendable.
Stars: ✭ 31 (-85.24%)
Mutual labels: queue, promise
P Queue
Promise queue with concurrency control
Stars: ✭ 1,863 (+787.14%)
Mutual labels: promise, queue
queue-promise
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
Stars: ✭ 56 (-73.33%)
Mutual labels: queue, promise
Promise Queue Plus
Promise-based queue. Support timeout, retry and so on.
Stars: ✭ 113 (-46.19%)
Mutual labels: promise, queue
Stevejobs
A simple jobs queue that just works (for Meteor.js)
Stars: ✭ 195 (-7.14%)
Mutual labels: queue
Django dramatiq
A Django app that integrates with Dramatiq.
Stars: ✭ 181 (-13.81%)
Mutual labels: queue
Node Instagram
Instagram api client for node that support promises.
Stars: ✭ 185 (-11.9%)
Mutual labels: promise
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (-7.14%)
Mutual labels: promise
Penpal
A promise-based library for securely communicating with iframes via postMessage.
Stars: ✭ 197 (-6.19%)
Mutual labels: promise
Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+970.95%)
Mutual labels: promise
Apisauce
Axios + standardized errors + request/response transforms.
Stars: ✭ 2,303 (+996.67%)
Mutual labels: promise
Chronicle Queue
Micro second messaging that stores everything to disk
Stars: ✭ 2,489 (+1085.24%)
Mutual labels: queue
promise-queue
Promise-based queue
Installation
promise-queue
can be installed using npm
:
npm install promise-queue
Interface
new Queue(Number maxConcurrent, Number maxQueued): Queue
-
Queue#add(Function generator): Promise
- adds function argument that generates a promise to the queue -
Queue#getQueueLength(): Number
- returns current length of buffer(added but not started promise generators)it <= maxQueued
-
Queue#getPendingLength(): Number
- returns number of pending(concurrently running) promisesit <= maxConcurrent
Example
Configure queue
By default Queue
tries to use global Promises, but you can specify your own promises.
Queue.configure(require('vow').Promise);
Or use old-style promises approach:
Queue.configure(function (handler) {
var dfd = $.Deferred();
try {
handler(dfd.resolve, dfd.reject, dfd.notify);
} catch (e) {
dfd.reject(e);
}
return dfd.promise();
});
Queue one by one example
var maxConcurrent = 1;
var maxQueue = Infinity;
var queue = new Queue(maxConcurrent, maxQueue);
app.get('/version/:user/:repo', function (req, res, next) {
queue.add(function () {
// Assume that this action is a way too expensive
// Call of this function will be delayed on second request
return downloadTarballFromGithub(req.params);
})
.then(parseJson('package.json'))
.then(function (package) {
res.send(package.version);
})
.catch(next);
});
Getting number of pending promises and queue(buffered promises) length
var maxConcurrent = 1;
var maxQueue = 1;
var queue = new Queue(maxConcurrent, maxQueue);
queue.add(function () {
queue.getQueueLength() === 0;
queue.getPendingLength() === 1;
return somePromise();
});
queue.add(function () {
queue.getQueueLength() === 0;
queue.getPendingLength() === 0;
return somePromise();
});
queue.getQueueLength() === 1;
queue.getPendingLength() === 1;
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].