Last active
February 14, 2018 19:40
-
-
Save realyze/1430a7ff2f0e600b69d7e7e898ff78db to your computer and use it in GitHub Desktop.
Pizza challenge
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 defer = (res, ms) => new Promise(resolve => setTimeout(() => resolve(res), ms)); | |
const makeDough = () => defer({add: () => {}}, 500); | |
const makeSauce = () => defer({determineCheese: () => 'cheddar'}, 250); | |
const grateCheese = () => defer({type: 'cheddar'}, 150); | |
async function makePizza(sauceType = 'red') { | |
const pDough = makeDough(); | |
const pSauce = makeSauce(sauceType); | |
const pCheese = pSauce.then(sauce => grateCheese(sauce.determineCheese())); | |
const [dough, sauce, cheese] = await Promise.all([pDough, pSauce, pCheese]); | |
dough.add(sauce); | |
dough.add(cheese); | |
return dough; | |
} | |
makePizza(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment