https://github.com/maximilianschmitt/sleepqueue
A promise-based queue that sleeps between callbacks.
https://github.com/maximilianschmitt/sleepqueue
Last synced: 3 months ago
JSON representation
A promise-based queue that sleeps between callbacks.
- Host: GitHub
- URL: https://github.com/maximilianschmitt/sleepqueue
- Owner: maximilianschmitt
- License: mit
- Created: 2015-05-24T19:44:55.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-28T01:00:14.000Z (about 10 years ago)
- Last Synced: 2025-03-11T19:42:49.615Z (4 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/sleepqueue
- Size: 125 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# sleepqueue
[](https://travis-ci.org/maximilianschmitt/sleepqueue) [](https://coveralls.io/r/maximilianschmitt/sleepqueue) [](https://www.npmjs.com/package/sleepqueue)
A promise-based queue that sleeps between callbacks.
## Installation
```
$ npm i sleepqueue -S
```## Usage
### General
```js
var sleepqueue = require('sleepqueue');// create a queue with an interval of 1 second
var queue = sleepqueue({ interval: 1000 });// `push` pushes to the end of the queue
queue.push(print('My name is'));
queue.push(print('My name is'));
queue.push(print('My name is'));
queue.push(print('Slim Shady'));// `unshift` pushes to the start of the queue
queue.unshift(print('Hi'));// just a helper function
function print(what) {
return function() {
console.log(what);
};
}
```Output:
```
Hi
# (wait 1 second)
My name is
# (wait 1 second)
My name is
# (wait 1 second)
My name is
# (wait 1 second)
Slim Shady
```### Errors
Uncaught errors and rejected promises will stop the queue and emit an error event.
```js
queue.push(print('Hello'));
queue.push(function() {
throw 'I stopped the queue';
});
queue.push(print('Bye'));queue.on('error', function(err) {
console.log('Error: ' + err);
});
```Output:
```
Hello
Error: I stopped the queue
```