Last active
October 6, 2016 15:19
-
-
Save juice49/dad97776d57c9d4b3a58cec2413a6ea2 to your computer and use it in GitHub Desktop.
Delay a JS promise
This file contains hidden or 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
const delay = delayPromise(1000) | |
delay(() => fetch('/')) | |
.then(console.log) |
This file contains hidden or 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
'use strict'; | |
const delayPromise = ms => createPromise => new Promise((resolve, reject) => { | |
setTimeout( | |
() => createPromise().then(resolve, reject), | |
ms | |
); | |
}); | |
export default delayPromise; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment