Non blocking asynchronous sleep, with watching condition.
The library has method:
timeout
- sleep time in milisecond,done
- callback runned always after sleep.
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.
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:
var options = { sleep: 1000, interval: 10 };
done
- callback runned always after sleep.
var sleep = require('sleep-async')();
sleep.sleep(5000, function(){
stopTime = new Date().getTime();
console.log('Difference: '+((stopTime-startTime)/1000)+' [s]');
});
sleep.sleepWithCondition(function(){
return collection.length >= 10;
},
5000,
function(){
stopTime = new Date().getTime();
console.log('Difference: '+((stopTime-startTime)/1000)+' [s]');
});
var options = {
sleep: 5000,
interval: 2500
};
sleep.sleepWithCondition(function(){
return collection.length >= 10;
},
options,
function(){
stopTime = new Date().getTime();
console.log('Difference: '+((stopTime-startTime)/1000)+' [s]');
});
If You like this library, please view example files.