promise-timers
v1.0.1
Published
Promise Timers
Downloads
837
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.setTimeout
delay
The number of milliseconds to wait before calling resolve....args
Optional arguments to pass when the resolve is executed.
PromiseTimers.setInterval
delay
The number of milliseconds to wait before calling resolve.method
A function that repeats on each interval. This function will fire upon each interval unless one of the following returns are implemented.- Return Value Actions
result
Any valid JavaScript error type. Will fire the reject and pass the error.result
A boolean that calls resolve if true or reject if false.result
Any thing returned besidesnull
,undefined
,false
, and a validError
type 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
...args
Optional arguments to pass when the resolve is executed.
PromiseTimers.setImmediate
...args
Optional arguments to pass when the resolve is executed.
PromiseTimers.clearTimeout
timeout
A Timeout object as returned by setInterval().
PromiseTimers.clearInterval
interval
A Interval object as returned by setInterval().
PromiseTimers.clearImmediate
immediate
An 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');
});