Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dimapaloskin/async-sleep
Sleep based on promise. Supports resolve and reject with defined response and error.
https://github.com/dimapaloskin/async-sleep
async-await async-sleep javascript promise sleep
Last synced: 7 days ago
JSON representation
Sleep based on promise. Supports resolve and reject with defined response and error.
- Host: GitHub
- URL: https://github.com/dimapaloskin/async-sleep
- Owner: dimapaloskin
- License: mit
- Created: 2016-11-30T16:02:54.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-03T14:47:32.000Z (almost 8 years ago)
- Last Synced: 2024-10-13T02:49:02.715Z (about 1 month ago)
- Topics: async-await, async-sleep, javascript, promise, sleep
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# async-sleep [![Build Status](https://travis-ci.org/dimapaloskin/async-sleep.svg?branch=master)](https://travis-ci.org/dimapaloskin/async-sleep)
Promise-based sleep that supports resolve and reject with defined results.
## Install
```
npm i --save async-sleep
```## Usage:
Use sleep function directly:
```js
import sleep from 'async-sleep'; // var sleep = require('async-sleep') also worksconst mock = {
message: 'Hello world'
};sleep(2000, mock).then(console.log); // { message: 'Hello world' }
```Use resolve method:
```js
import sleep from 'async-sleep';const mock = {
message: 'Hello world'
};sleep.resolve(2000, mock).then(console.log); // { message: 'Hello world' }
```Use reject method:
```js
import sleep from 'async-sleep';const mock = {
error: 'Something went wrong...'
};sleep.reject(2000, mock)
.then(() => console.log('this message will never be shown'))
.catch(console.log); // { error: 'Something went wrong...' }
```Use randomResolve method:
```js
import sleep from 'async-sleep';const mock = {
message: 'Hello world'
};sleep.randomResolve(100, 1000, mock).then(console.log); // { message: 'Hello world' }
```Use randomReject method:
```js
import sleep from 'async-sleep';const mock = {
error: 'Something went wrong...'
};sleep.randomReject(100, 1000, mock)
.then(() => console.log('this message will never be shown'))
.catch(console.log); // { error: 'Something went wrong...' }
```## API
#### sleep(ms, [result])
#### sleep.resolve(ms, [result]);
#### sleep.reject(ms, [error]);
#### sleep.randomResolve(minMs, maxMs, [result]);
#### sleep.randomReject(minMs, maxMs, [error]);## Author
[Dmitry Pavlovsky](http://palosk.in)