๐Ÿ’พ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?