Create a queue to limit async execution in time
// Execute 5 functions at the same time, but never more than 5 per second.
const queue = require('@ivanbeldad/timed-queue').create({ items: 5, time: 1000 })
queue.add(myPromise)
.then(result => console.log(`My result after completed! => ${result}`))
.catch(error => console.error(`Oh no! After all the work it failed! => ${error}`))
try {
const result = await queue.add(myAsyncFunction)
console.log(`My result after completed! => ${result}`))
} catch (error) {
console.error(`Oh no! After all the work it failed! => ${error}`))
}
Timed Queue is open-sourced software licensed under the MIT license.