An open API service indexing awesome lists of open source software.

https://github.com/ivanbeldad/timed-queue

Create a queue to limit async execution in time. The main motivation is to prevent API's quota limits
https://github.com/ivanbeldad/timed-queue

async nodejs queue

Last synced: 6 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# Timed Queue



[![NPM Version](https://img.shields.io/npm/v/@ivanbeldad/timed-queue.svg)](https://www.npmjs.com/package/@ivanbeldad/timed-queue)
[![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://github.com/ivanbeldad/timed-queue/blob/master/LICENSE)

Create a queue to limit async execution in time

## Examples

```javascript
// 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

```javascript
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

```javascript
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](https://github.com/ivanbeldad/timed-queue/blob/master/LICENSE).