Skip to content

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

License

Notifications You must be signed in to change notification settings

ivanbeldad/timed-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published