Skip to content

Instantly share code, notes, and snippets.

@beatak
Created February 21, 2015 01:43
Show Gist options
  • Save beatak/889377d569e22b8a5a28 to your computer and use it in GitHub Desktop.
Save beatak/889377d569e22b8a5a28 to your computer and use it in GitHub Desktop.
(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);
}
)
})();
(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);
}
)
})();
(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