Last active
May 29, 2023 02:59
-
-
Save yongjun21/3078f265703a731011a92f4959223eca to your computer and use it in GitHub Desktop.
Alternative implementation of timed delay decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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