Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
concurrent-promise-queue
Advanced tools
Allows promises to be queued up and executed at a maximum rate defined by time or max concurrency
A small utility for throttling the rate at which promises are executed.
It can set a maximum number of promises to run concurrently, for example running a list of promises 1 or 2 at a time.
It can run promises according to a time based rate-limit, for example running at most 1 promise every second, or 10 promises every 5 seconds.
npm install --save concurrent-promise-queue
Generally this is useful if you have a lot of resources to call, but you do not want to overload your server by attempting to do them all at the same time.
For example, making 100 HTTP Requests, if all 100 Requests occur at the same time it is likely the server will run out of memory on a small server. So using Concurrent Promise Queue allows the server to process say, 5 at a time, to ensure it does not run out of memory.
import {ConcurrentPromiseQueue} from "concurrent-promise-queue";
// Setting maxNumberOfConcurrentPromises to 1 means promises will be run one after another
const queue = new ConcurrentPromiseQueue({ maxNumberOfConcurrentPromises: 1 });
return Promise.all([
queue.addPromise(() => callApi('/book/1')),
queue.addPromise(() => callApi('/book/2')),
queue.addPromise(() => callApi('/book/3')),
queue.addPromise(() => callApi('/book/4')),
queue.addPromise(() => callApi('/book/5')),
queue.addPromise(() => callApi('/book/6')),
])
.then(results => {
// do something with the results
return results
})
0s - Called /book/1
1s - Called /book/2
2s - Called /book/3
3s - Called /book/4
4s - Called /book/5
5s - Called /book/6
import {ConcurrentPromiseQueue} from "concurrent-promise-queue";
// Setting maxNumberOfConcurrentPromises to 2
// means that at most, 2 promises will be executed at any one time
const queue = new ConcurrentPromiseQueue({ maxNumberOfConcurrentPromises: 2 });
return Promise.all([
queue.addPromise(() => callApi('/book/1')),
queue.addPromise(() => callApi('/book/2')),
queue.addPromise(() => callApi('/book/3')),
queue.addPromise(() => callApi('/book/4')),
queue.addPromise(() => callApi('/book/5')),
queue.addPromise(() => callApi('/book/6')),
])
.then(results => {
// do something with the results
return results
})
The queue will start new promises to maintain the concurrency limit.
0s - Called /book/1
0s - Called /book/2
1s - Called /book/3
1s - Called /book/4
2s - Called /book/5
2s - Called /book/6
import {ConcurrentPromiseQueue} from "concurrent-promise-queue";
// Setting unitOfTimeMillis to 4000
// Setting maxThroughputPerUnitTime to 2
// means that at most, 2 promises will be executed per 4 seconds
const queue = new ConcurrentPromiseQueue({
unitOfTimeMillis: 4000,
maxThroughputPerUnitTime: 2,
});
return Promise.all([
queue.addPromise(() => callApi('/book/1')),
queue.addPromise(() => callApi('/book/2')),
queue.addPromise(() => callApi('/book/3')),
queue.addPromise(() => callApi('/book/4')),
queue.addPromise(() => callApi('/book/5')),
queue.addPromise(() => callApi('/book/6')),
])
.then(results => {
// do something with the results
return results
})
The queue will start new promises to maintain the concurrency limit.
0s - Called /book/1
0s - Called /book/2
4s - Called /book/3
4s - Called /book/4
8s - Called /book/5
8s - Called /book/6
FAQs
Allows promises to be queued up and executed at a maximum rate defined by time or max concurrency
We found that concurrent-promise-queue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.