Skip to content

Instantly share code, notes, and snippets.

@philpoore
Last active January 17, 2016 18:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philpoore/32eaf50eec6451e89f6a to your computer and use it in GitHub Desktop.
Save philpoore/32eaf50eec6451e89f6a to your computer and use it in GitHub Desktop.
Javascript Delay Promise with Arguments
// Delay a JS Promise by a number
// of miliseconds. Preserves arguments.
const delayPromise = (duration) => {
return (...args) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(...args);
}, duration);
});
};
};
const thing = () => {
  // returns a promise with data
}

thing()
	.then(delayPromise(100))
	.then((data) => {
		console.log(data);
	});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment