Sleep-Async
Non blocking asynchronous sleep, with watching condition.
The library have two version:
- Classic - standard methods with callback function
- How to initialize object? e.g.
const sleep = require('sleep-async')();
- How to initialize object? e.g.
- Promise - the methods returns Promise object
- How to initialize object? e.g.
const sleep = require('sleep-async')().Promise;
- How to initialize object? e.g.
Classic library has methods:
-
sleep(timeout, done)
timeout
- sleep time in milisecond,done
- callback runned always after sleep.
-
sleepWithCondition(condition, timeout, done)
condition
- condition function has checked on any sleep cycle. When condition is true, the sleep is done.timeout
- max timeout to sleep.done
- callback runned always after sleep.
-
sleepWithCondition(condition, options, done)
condition
- condition function has checked on any sleep cycle. When condition is true, the sleep is done.options
- advanced options for sleep.- full options example:const options =sleep: 1000interval: 10;
- full options example:
done
- callback runned always after sleep.
Quick exaples
-
Required
const sleep = ; -
With
sleep(timeout, done)
sleep; -
With
sleepWithCondition(condition, timeout, done)
sleep; -
With
sleepWithCondition(condition, options, done)
const options =sleep: 5000interval: 2500;sleep;
Promise library has methods:
-
sleep(timeout) : Promise
timeout
- sleep time in milisecond
-
sleepWithCondition(condition, timeout) : Promise
condition
- condition function has checked on any sleep cycle. When condition is true, the sleep is done.timeout
- max timeout to sleep.
-
sleepWithCondition(condition, options) : Promise
condition
- condition function has checked on any sleep cycle. When condition is true, the sleep is done.options
- advanced options for sleep.- full options example:const options =sleep: 1000interval: 10;
- full options example:
Quick exaples
-
Required
const sleep = Promise; -
With
sleep(timeout)
const startTime = ;sleep; -
With
sleepWithCondition(condition, timeout)
const startTime = ;sleep; -
With
sleepWithCondition(condition, options)
const options =sleep: 5000interval: 2500;const startTime = ;sleep;