Skip to content
Subhajit Sahu edited this page Jul 29, 2022 · 2 revisions

Generate delayed version of a function.

Similar: defer, delay.


function delay(x, t)
// x: a function
// t: delay time (ms)
const xfunction = require('extra-function');


var count = 0;
var fn = xfunction.delay(() => ++count, 500);
setTimeout(fn, 0);
setTimeout(fn, 1000);
// `count` incremented after 0.5s
// `count` incremented after 1.5s


var count = 0;
var fn = xfunction.delay(() => ++count, 500);
setTimeout(fn, 0);
setTimeout(fn, 1000);
setTimeout(fn, 2000);
setTimeout(fn, 3000);
// `count` incremented after 0.5s
// `count` incremented after 1.5s
// `count` incremented after 2.5s
// `count` incremented after 3.5s


References

Clone this wiki locally