Skip to content

Instantly share code, notes, and snippets.

@keyvan-m-sadeghi
Created February 16, 2019 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyvan-m-sadeghi/9bf5c9a99fb5e5d5fc9d2566a110c6b3 to your computer and use it in GitHub Desktop.
Save keyvan-m-sadeghi/9bf5c9a99fb5e5d5fc9d2566a110c6b3 to your computer and use it in GitHub Desktop.
const delay = milliseconds => new Nancy(resolve => setTimeout(resolve, milliseconds));
const logThenDelay = milliseconds => total => {
console.log(`${total / 1000.0} seconds!`);
return delay(milliseconds)
.then(() => total + milliseconds);
};
logThenDelay(500)(0) // logs 0 seconds!
.then(logThenDelay(500)) // after 0.5 seconds, logs 0.5 seconds!
.then(logThenDelay(500)) // after 1 second, logs 1 seconds!
.then(logThenDelay(500)); // after 1.5 seconds, logs 1.5 seconds!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment