๐พPromise.wait()
๐พ replit๏ผPromise.wait()
// โญ Promise.wait()
Promise.wait = function(seconds) {
return new Promise((resolve, _) => { // this Promise never rejects.
// do not wait if `seconds` not positive.
if (!(seconds > 0)) seconds = 0;
// invoking resolve() with no arguments means
// that the Promise will always fulfill with value `undefined`.
setTimeout(resolve, seconds * 1000);
});
};
๐็ฏไพ๏ผ
Promise
.wait(2) // wait for 2 seconds
.then(_ => console.log('hello'));
Last updated
Was this helpful?