Skip to content

Instantly share code, notes, and snippets.

@srph
Last active May 17, 2018 08:28
Show Gist options
  • Save srph/cf5313c020efbcad615555018167f50e to your computer and use it in GitHub Desktop.
Save srph/cf5313c020efbcad615555018167f50e to your computer and use it in GitHub Desktop.
Add a delay between each ajax call
export default function delay(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
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