promise-timers
v1.0.1
Published
Promise Timers
Downloads
300
Maintainers
Readme
DEPRECATED (This project has been moved to https://github.com/AlexanderElias/promise-tool)
Promise Timers
A promised library of timers for Node.js and the browser. If you know the WindowTimers and promises you know how to use PromiseTimers.
Install
npm install promise-timers
API
PromiseTimers.setTimeoutdelayThe number of milliseconds to wait before calling resolve....argsOptional arguments to pass when the resolve is executed.
PromiseTimers.setIntervaldelayThe number of milliseconds to wait before calling resolve.methodA function that repeats on each interval. This function will fire upon each interval unless one of the following returns are implemented.- Return Value Actions
resultAny valid JavaScript error type. Will fire the reject and pass the error.resultA boolean that calls resolve if true or reject if false.resultAny thing returned besidesnull,undefined,false, and a validErrortype will resolve with that return value as the first argument.result<Null, Undefined> Both are ignored and will not trigger the resolve or reject.
- Return Value Actions
...argsOptional arguments to pass when the resolve is executed.
PromiseTimers.setImmediate...argsOptional arguments to pass when the resolve is executed.
PromiseTimers.clearTimeouttimeoutA Timeout object as returned by setInterval().
PromiseTimers.clearIntervalintervalA Interval object as returned by setInterval().
PromiseTimers.clearImmediateimmediateAn Immediate object as returned by setImmediate().
Example
const PromiseTimers = require('promise-timers');
const delay = 500;
PromiseTimers.setTimeout(delay).then(function (args) {
// this refers to timeout
console.log(args);
console.log('timeout done');
});
var i = 0;
function method () {
// this refers to interval
if (i > 5) {
return true;
} else {
console.log(i);
i++;
}
};
PromiseTimers.setInterval(delay, method).then(function (args) {
// this refers to interval
console.log(args);
console.log('interval done');
});
PromiseTimers.setImmediate().then(function (args) {
// this refers to immediate
console.log(args);
console.log('immediate done');
});
