javascript async delay
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
(async () => {
console.log('1');
await delay(1000);
console.log('2');
})();
javascript async delay
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
(async () => {
console.log('1');
await delay(1000);
console.log('2');
})();
async await
async function showAvatar() {
// read our JSON
let response = await fetch('/article/promise-chaining/user.json');
let user = await response.json();
// read github user
let githubResponse = await fetch(`https://api.github.com/users/${user.name}`);
let githubUser = await githubResponse.json();
// show the avatar
let img = document.createElement('img');
img.src = githubUser.avatar_url;
img.className = "promise-avatar-example";
document.body.append(img);
// wait 3 seconds
await new Promise((resolve, reject) => setTimeout(resolve, 3000));
img.remove();
return githubUser;
}
showAvatar();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us