Last active
April 27, 2016 09:00
-
-
Save maxfarseer/88458bd2284fb6b31459a605b80d6ba9 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
// won't work correctly | |
let counter = 0; | |
function delay(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(function() { | |
console.log(++counter) | |
resolve() | |
}, ms); | |
}); | |
} | |
delay(1000) | |
.then(delay(1000)) | |
.then(delay(2000)) | |
.then(() => console.log("Hello!")) | |
// --- | |
// work correctly | |
let counter = 0; | |
function delay(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(function() { | |
console.log(++counter) | |
resolve() | |
}, ms); | |
}); | |
} | |
delay(1000) | |
.then(() => delay(1000)) | |
.then(() => delay(2000)) | |
.then(() => console.log("Hello!")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment