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 makeSoup() { | |
const pot = boilPot(); | |
chopCarrots(); | |
chopOnions(); | |
await pot; | |
addCarrots(); | |
await letPotKeepBoiling(5); | |
addOnions(); | |
await letPotKeepBoiling(10); | |
console.log("Your vegetable soup is ready!"); |
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 chopCarrots() { | |
/** | |
* Some long computational task here... | |
*/ | |
console.log("Done chopping carrots!"); | |
} | |
function chopOnions() { | |
/** |
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 letPotKeepBoiling(time) { | |
return /* A promise to let the pot keep boilng for certain time */ | |
} | |
async function boilPot() { | |
return /* A promise to let the pot boil for time */ | |
} |
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 asyncFunction() { | |
/* Returns a promise... */ | |
} | |
result = await asyncFunction(); |
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 makeSoup() { | |
const pot = boilPot(); | |
chopCarrots(); | |
chopOnions(); | |
await pot; | |
addCarrots(); | |
await letPotKeepBoiling(5); | |
addOnions(); | |
await letPotKeepBoiling(10); | |
console.log("Your vegetable soup is ready!"); |
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 makeSoup() { | |
const pot = boilPot(); | |
chopCarrots(); | |
chopOnions(); | |
await pot; | |
addCarrots(); | |
await letPotKeepBoiling(5); | |
addOnions(); | |
await letPotKeepBoiling(10); |
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
makeSoup(); | |
makePasta(); |
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 callbackHell() { | |
boilPot(() => { | |
addCarrots(); | |
letPotKeepBoiling( | |
() => { | |
addOnions(); | |
letPotKeepBoiling( | |
() => { | |
console.log("Your vegetable soup is ready!"); | |
}, |
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 makeSoup() { | |
return Promise.all([ | |
new Promise((reject, resolve) => { | |
chopCarrots(); | |
chopOnions(); | |
resolve(); | |
}), | |
boilPot() | |
]).then(() => { | |
addCarrots(); |
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 myArray = [1, 4, 9, 16]; | |
function timesTwo(x) { | |
return x * 2; | |
} | |
// Pass the function to a map | |
const mappedArray = myArray.map(timesTwo); |
OlderNewer