Created
February 16, 2019 21:05
-
-
Save keyvan-m-sadeghi/9bf5c9a99fb5e5d5fc9d2566a110c6b3 to your computer and use it in GitHub Desktop.
This file contains 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
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