Similar to this question, but rather than asking about how promises work in general, I specifically want to know:
What is the standard/best way to wrap setTimeout in
Here's how I'd implement it:
function delay(duration, func) {
var args = Array.prototype.slice.call(arguments, 2);
return new Promise(function (resolve) {
setTimeout(function () {
resolve(func.apply(null, args));
}, duration);
});
}
(ES5-syntax intentionally chosen)
But maybe there's a common library that already does this, or a better way to do it.