Skip to content

Instantly share code, notes, and snippets.

@yongjun21
Last active May 29, 2023 02:59
Show Gist options
  • Save yongjun21/3078f265703a731011a92f4959223eca to your computer and use it in GitHub Desktop.
Save yongjun21/3078f265703a731011a92f4959223eca to your computer and use it in GitHub Desktop.
Alternative implementation of timed delay decorators
function delay (invoke, ms) {
return (...args) => new Promise(resolve => {
setTimeout(resolve, ms)
}).then(() => invoke.apply(...args))
}
function delay2 (invoke, ms) {
return (...args) => new Promise(resolve => {
setTimeout(resolve, ms, invoke(...args))
})
}
/* Usage
Promise.waterfall(array, delay(invoke, 1000))
Promise.waterfall(array, delay2(invoke, 1000))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment