StevenSchlotterbeck
9/14/2018 - 8:56 PM

sleep.js

// Used to pause execution
const pause = ms => new Promise(resolve => setTimeout(resolve, ms));

/**
 * Pauses execution for a given amount of time.
 * @param {integer} time - The amount of time to sleep for
 * @param {function} fn  - A runction to execute when the sleep is done
 * @param {...any} args  - Arguments to pass to the function
 */
async function sleep(time, fn, ...args) {
    await pause(time);
    return fn(...args);
}