Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@riteable/q-worker
Advanced tools
Rate limit and queue async functions.
This module lets you queue up async tasks to be executed at a predetermined interval. For example, if you're working with a REST API that's rate limited, you can use this module to only execute requests X amount of times per second.
You can install using npm:
$ npm i @riteable/q-worker
const worker = require('q-worker')
const queue = worker({
delay: 1000,
concurrent: 1
})
function someAsyncTask () {
return new Promise((resolve) => {
setTimeout(() => resolve(new Date()), 100)
})
}
const task1 = queue.add(someAsyncTask)
const task2 = queue.add(someAsyncTask)
const task3 = queue.add(someAsyncTask)
Promise.all([task1, task2, task3])
.then(console.log)
.catch(console.error)
The console.log
would output something like the following:
[
2020-09-17T12:00:56.471Z,
2020-09-17T12:00:57.474Z,
2020-09-17T12:00:58.474Z
]
The output shows the timestamps are all 1 second (1000ms) apart, which is determined by the delay: 1000
setting.
If the concurrent
option is set to 2
, you might get something like this:
[
2020-09-17T12:04:15.035Z,
2020-09-17T12:04:15.035Z,
2020-09-17T12:04:16.038Z
]
The first two tasks are executed at the same time, but the third task is delayed by the delay
amount.
delay
: The amounts of milliseconds between tasks.concurrent
: The amount of tasks executed at the same time.Available on the configured object, eg.: queue.add()
.
add(fn)
: Add an async function to the queue.Available on the configured object, through the events
key, eg.: queue.events.on()
.
'done'
: Fired when all tasks are done executing.FAQs
Rate limit and queue async functions.
The npm package @riteable/q-worker receives a total of 5 weekly downloads. As such, @riteable/q-worker popularity was classified as not popular.
We found that @riteable/q-worker 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.