Skip to content

Instantly share code, notes, and snippets.

@anotherxx
Created September 9, 2017 14:44
Show Gist options
  • Save anotherxx/52d39426a94a74346f3c5eed97cece4d to your computer and use it in GitHub Desktop.
Save anotherxx/52d39426a94a74346f3c5eed97cece4d to your computer and use it in GitHub Desktop.
httpGetUser('http://localhost:3000/users')
.then(response =>
{
console.log('First resolve callback');
console.log('~~~~~~~~~~');
var user = JSON.parse(response);
user = user.find((user) => user.name == 'Nerhbest');
return user.name;
}).then(user =>
{
console.log('second callback');
console.log(user);
return httpGetUser(`https://api.github.com/users/${user}`); //Ecли resovle callback возвращает promise то все оставшиеся callbacks ждут выполнения запроса , и в след коллбек передастся результат вызова api
}).then(githubUser =>
{
console.log(githubUser);
let gituser = JSON.parse(githubUser);
console.log(gituser);
let img = new Image();
img.src = gituser.avatar_url;
document.body.appendChild(img);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment