Created
September 18, 2017 21:18
-
-
Save joelbarbosa/c29a3938a37fa26f207dc54014718718 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/jazelig
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var a = new Promise(res => setTimeout(()=>{ | |
res(1) | |
}, 2000)); | |
var b = new Promise(res => setTimeout(()=>{ | |
res(2) | |
}, 1000)); | |
var c = (fn) => new Promise(res => console.log(fn)); | |
var arr = [a, b]; | |
arr.reduce(function(promise, next) { | |
return promise.then(_ => next).then( value => { | |
console.log(value); // *** | |
return value; | |
}); | |
}, Promise.resolve()); | |
//hardcode | |
a.then(r1 => r1.then(c(r1).then(b.then(r2 => r2.then(c(r2)))))) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var a = new Promise(res => setTimeout(()=>{ | |
res(1) | |
}, 2000)); | |
var b = new Promise(res => setTimeout(()=>{ | |
res(2) | |
}, 1000)); | |
var c = (fn) => new Promise(res => console.log(fn)); | |
var arr = [a, b]; | |
arr.reduce(function(promise, next) { | |
return promise.then(_ => next).then( value => { | |
console.log(value); // *** | |
return value; | |
}); | |
}, Promise.resolve()); | |
//hardcode | |
a.then(r1 => r1.then(c(r1).then(b.then(r2 => r2.then(c(r2))))))</script></body> | |
</html> |
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
var a = new Promise(res => setTimeout(()=>{ | |
res(1) | |
}, 2000)); | |
var b = new Promise(res => setTimeout(()=>{ | |
res(2) | |
}, 1000)); | |
var c = (fn) => new Promise(res => console.log(fn)); | |
var arr = [a, b]; | |
arr.reduce(function(promise, next) { | |
return promise.then(_ => next).then( value => { | |
console.log(value); // *** | |
return value; | |
}); | |
}, Promise.resolve()); | |
//hardcode | |
a.then(r1 => r1.then(c(r1).then(b.then(r2 => r2.then(c(r2)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment