ivanbeldad / timed-queue

Create a queue to limit async execution in time. The main motivation is to prevent API's quota limits

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timed Queue

NPM Version License: MIT

Create a queue to limit async execution in time

Examples

// 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 })

Promises approach example

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}`))

Async/Await approach example

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}`))
}

License

Timed Queue is open-sourced software licensed under the MIT license.

About

Create a queue to limit async execution in time. The main motivation is to prevent API's quota limits

License:MIT License


Languages

Language:JavaScript 100.0%