delay-set-timeout
Call setTimeout() with min/max delay.
- If an old timer is waiting, before min-delay, a new calling will cancel the old one;
- If there is no more new calling, the last timer will be executed after min-delay, but certainly before the max-delay, or before the earliest one of multiple max-delays;
Install
npm install delay-set-timeout
Usage & Api
var delay_set_timeout = require("delay-set-timeout");
var tmid = null;
var ret = [];
tmid = delay_set_timeout(
function () { ret.push(1); },
201,
tmid,
402
);
setTimeout(
function () {
tmid = delay_set_timeout(
function () {
ret.push(2);
},
103,
tmid,
404
);
},
105
);
setTimeout(
function () {
tmid = delay_set_timeout(
function () {
ret.push(3);
console.log(ret.join(","));
},
106,
tmid,
407
);
},
308
);