Terence
December 24, 2020, 12:49pm
1
return getUser(1)
.then(user => { getRepositories(user)} )
.then(repo => { getCommits(repo) } )
.then(commit => {console.log(“COMMIT” , commit)})
.catch(error => console.log(error) ) ;
After placing the curly bracket , the promise doesn’ t wait for the result before execute the next promise .
SAM
December 24, 2020, 1:04pm
2
Your code blocks in curly braces don’t return anything. So the then
s will all immediately return a resolved promise. Either remove the curly braces or let your code blocks return a promise.
Terence
December 24, 2020, 1:15pm
3
Thanks. Problem solved but still don’t get the idea between placing a brackets will affect not returning the Promise ?
SAM
December 24, 2020, 3:14pm
4
When you use curly braces you declare a code block. Code blocks don’t have a value unless you explicitly return
one. Think of a code block
{
getRepositories(user)};
getCommits(repo);
}
Which of of the two promises should be the value the code block evaluates to?