
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
simple-promise-queue
Advanced tools
This is a simple queue where you can push a function(resolve, reject)
to a queue and
get a promise that references that task.
npm install simple-promise-queue
Promise.all
Queue.pushTask(function(resolve, reject) { ... })
Puts a task at the end of the queue. Returns a Promise.
Queue.unshiftTask(function(resolve, reject) { ... })
Puts a task at the beginning of the queue. Returns a Promise.
simple-promise-queue
inherits from queue, so check that out for other methods.
Note: I added an option autoStart
that can be passed into the constructor so the queue
will automatically start whenever something is pushed into it.
Adding your own Promise implementation:
var Queue = require('simple-promise-queue');
Queue.setPromise(require('bluebird'));
Pushing a task to the queue and getting a promise:
var Queue = require('simple-promise-queue');
var queue = new Queue({
autoStart: true, // autostart the queue
});
var promise = queue.pushTask(function(resolve, reject) {
// do some task here to fetch results
resolve('results');
});
promise.then(function(results) {
// process the results here
});
A useful example of this would be if you had Promise.all
but wanted to only throttle
it to run 5 tasks at a time:
var Queue = require('simple-promise-queue');
var queue = new Queue({
autoStart: true, // autostart the queue
concurrency: 5
});
var promiseArr = [];
var updateUserInDb = function(id) {
var promise = queue.pushTask(function(resolve, reject) {
// do a query to update the user here and
resolve('done');
});
promiseArr.push(promise);
};
var promiseArr = [];
for (var id = 0; id < 100; id++) {
queue.updateUserInDb(id);
}
Promise.all(promiseArr).then(function() {
// will call this after all the updates have been run
});
Here is an example where you have 2 jobs (each having 2 tasks) to complete and want to know when each job is finished individually.
var Queue = require('simple-promise-queue');
var queue = new Queue({
autoStart: true, // autostart the queue
concurrency: 3
});
var job1Part1 = queue.pushTask(function(resolve, reject) {
// some limited resource async task that takes 5 seconds
setTimeout(function() {
resolve('promise 1 done');
}, 5000);
});
var job1Part2 = queue.pushTask(function(resolve, reject) {
// some limited resource async task that takes 3 seconds
setTimeout(function() {
resolve('promise 2 done');
}, 3000);
});
var job2Part1 = queue.pushTask(function(resolve, reject) {
// some limited resource async task that takes 5 seconds
setTimeout(function() {
resolve('promise 1 done');
}, 5000);
});
var job2Part2 = queue.pushTask(function(resolve, reject) {
// some limited resource async task that takes 3 seconds
setTimeout(function() {
resolve('promise 2 done');
}, 3000);
});
Promise.all([job1Part1, job1Part2]).then(function(values) {
// this should take 5 seconds to reach here
});
Promise.all([job2Part1, job2Part2]).then(function(values) {
// this should take 8 seconds to reach here
});
./node_modules/mocha/bin/mocha
FAQs
queue where you can push promise-like functions
The npm package simple-promise-queue receives a total of 254 weekly downloads. As such, simple-promise-queue popularity was classified as not popular.
We found that simple-promise-queue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.