Created
February 21, 2015 01:43
-
-
Save beatak/889377d569e22b8a5a28 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function () { | |
var c = Date.now(); | |
console.log('start: ' + c); | |
new Promise( | |
function (res, rej) { | |
setTimeout(function (){ | |
console.log('1st fullfilled at ' + Date.now()); | |
res(1); | |
}, 1000); | |
} | |
).then( | |
function (res) { | |
console.log('2nd then with ', arguments); | |
return new Promise( | |
function (_res, _rej){ | |
setTimeout(function (){ | |
console.log('2nd fullfilled at ' + Date.now()); | |
_res(2); | |
}, 1000); | |
} | |
); | |
} | |
).then( | |
function (res) { | |
console.log('3rd then with ', arguments); | |
console.log(Date.now() - c); | |
} | |
) | |
})(); |
This file contains hidden or 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
(function () { | |
var c = Date.now(); | |
Promise.all([ | |
new Promise(function (res) {setTimeout(function () {res(3000);}, 3000);}), | |
new Promise(function (res) {setTimeout(function () {res(2000);}, 2000);}), | |
new Promise(function (res) {setTimeout(function () {res(1000);}, 1000);}) | |
]).then( | |
function () { | |
console.log('THEN: ' + (Date.now() - c)); | |
console.log(arguments); | |
} | |
) | |
})(); |
This file contains hidden or 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
(function () { | |
var c = Date.now(); | |
console.log('start: ' + c); | |
new Promise( | |
function (res, rej) { | |
setTimeout(function (){ | |
console.log('1st fullfilled at ' + Date.now()); | |
res(1); | |
}, 1000); | |
} | |
).then( | |
function (res, rej) { | |
console.log('2nd then with ', arguments); | |
new Promise( | |
function (_res, _rej){ | |
setTimeout(function (){ | |
console.log('2nd fullfilled at ' + Date.now()); | |
_res(2); | |
}, 1000); | |
} | |
); | |
} | |
).then( | |
function (res, rej) { | |
console.log('3rd then with ', arguments); | |
console.log(Date.now() - c); | |
} | |
) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment