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
posts.forEach(post => { | |
promise = promise.then(db.insert(post)); | |
}); |
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
let promise = Promise.resolve(); | |
const posts = [{}, {}, {}]; | |
posts.forEach(post => { | |
promise = promise.then(() => { | |
return db.insert(post); | |
}); | |
}); | |
promise.then(() => { |
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
async function makeRequest() { | |
const response = await fetch('foo'); | |
if (response.doestItNeedAnotherRequest) { | |
const secondResponse = await makeAnotherRequest(response); | |
console.log(secondResponse); | |
return secondResponse; | |
} | |
console.log(response); | |
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
function makeRequest() { | |
return fetch('foo') | |
.then(response => { | |
if (data.doesItNeedAnotherRequest) { | |
return makeAnotherRequest(response) | |
.then(secondResponse => { | |
console.log(secondResponse); | |
return secondResponse; | |
}); |
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
async function makeRequest() { | |
try { | |
const result = JSON.parse(await fetch('foo')); | |
console.log(result); | |
} catch (error) { | |
console.log(error); | |
} | |
} |
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
function makeRequest() { | |
try { | |
fetch('foo') | |
.then(response => { | |
const result = JSON.parse(response); | |
console.log(result); | |
}) | |
.catch(error => { | |
console.log(error); |
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
async function myAsyncFunction() { | |
try { | |
const result = await somethingThatReturnsAPromise(); | |
console.log(result); | |
} catch (error) { | |
console.log(error); | |
} | |
} |
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
async function myAsyncFunction() { | |
const result = await somethingThatReturnsAPromise(); | |
console.log(result); | |
} |
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
async function getFromGitHub() { | |
try { | |
const userName = 'patarkf'; | |
const url = 'https://api.github.com/users'; | |
const reposResponse = await fetch(`${url}/${userName}/repos`); | |
const userRepos = await reposResponse.json(); | |
console.log(userRepos); | |
} catch (error) { | |
console.log(error); |
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
function getFromGitHub() { | |
const userName = 'patarkf'; | |
const url = 'https://api.github.com/users'; | |
fetch(`${url}/${userName}/repos`) | |
.then(reposResponse => { | |
return reposResponse.json(); | |
}) | |
.then(userRepos => { | |
console.log(userRepos); |