nano-timer
v1.0.1
Published
A delayed Promise
Downloads
2
Readme
nano-timer
A delayed Promise.
API
var timer = require('nano-timer');
timer(100/*ms*/, 'ok').then(function (v) {
assert.strictEqual(v, 'ok');
}).catch(function (e) {
console.error(e);
});
timer(time, ...)
time
Number -- delay of promise resolve in milliseconds- ... -- resolve arguments
Creates Promise with postponed resolve. It can be cancelled.
var timer = require('nano-timer'),
Promise = require('nano-promise');
var delay = timer(100/*ms*/, 'ok').then(function (v) {
assert.strictEqual(v, 'ok');
}).catch(function (e) {
if (e === Promise.CANCEL_REASON)
console.log('Cancelled!');
else
console.error(e);
});
timer.cancel(); // will output Promise.CANCEL_REASON to console.