Last active
May 17, 2018 08:28
-
-
Save srph/cf5313c020efbcad615555018167f50e to your computer and use it in GitHub Desktop.
Add a delay between each ajax call
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
export default function delay(ms) { | |
return new Promise(resolve => { | |
setTimeout(resolve, ms) | |
}) | |
} |
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
import series from 'p-series' | |
series([ | |
() => requestX(), | |
() => delay(1000), | |
() => requestY(), | |
() => delay(1000), | |
() => requextZ() | |
]).then(([resX, resY, resZ]) => { | |
// Do something | |
}, err => { | |
// Do something with the error | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment