Skip to content

Instantly share code, notes, and snippets.

@juice49
Last active October 6, 2016 15:19
Show Gist options
  • Save juice49/dad97776d57c9d4b3a58cec2413a6ea2 to your computer and use it in GitHub Desktop.
Save juice49/dad97776d57c9d4b3a58cec2413a6ea2 to your computer and use it in GitHub Desktop.
Delay a JS promise
const delay = delayPromise(1000)
delay(() => fetch('/'))
.then(console.log)
'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