Created
October 30, 2017 19:38
-
-
Save SastraNababan/17e7fd24388317a2871adcf4f4e67587 to your computer and use it in GitHub Desktop.
Promise Chain Example 2
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 getPost = () => fetch('https://jsonplaceholder.typicode.com/posts/1') | |
const getAuthor = (id) => fetch('https://jsonplaceholder.typicode.com/users/' + id) | |
const getComment = (id) => fetch('https://jsonplaceholder.typicode.com/users/' + id) | |
var a = getPost().then(res => res.json()) // #1 get post | |
var b = a.then(res => getAuthor(res.id)).then(res => res.json()) // #2 get author | |
var c = a.then(res => getComment(res.id)).then(res => res.json()) //#3 get comment | |
Promise.all([a,b,c]).then(results => { | |
console.log(results[0]) | |
console.log(results[1]) | |
console.log(results[2]) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment