Last active
August 21, 2020 20:43
Revisions
-
jh3y revised this gist
Dec 14, 2019 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ const PROB = 0.2 const grabIngredient = ingredient => () => { return new Promise((resolve, reject) => { setTimeout(() => { @@ -33,7 +33,7 @@ const getIngredientsFromTheSuperMarket = async () => { } catch(e) { return e } } const getIngredientsOnline = async () => await Promise.all([ getButter(), getFlour(), getSugar(), @@ -51,6 +51,7 @@ const bakeACake = async () => { const cakeMix = await mix(ingredients) const hotCake = await cook(cakeMix) const cake = await stand(hotCake) console.info('BAKED', cake) return cake } catch (e) { console.info(e) } } -
jh3y revised this gist
Dec 14, 2019 . 1 changed file with 14 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ const PROB = 0.1 const grabIngredient = ingredient => () => { return new Promise((resolve, reject) => { setTimeout(() => { @@ -33,30 +33,26 @@ const getIngredientsFromTheSuperMarket = async () => { } catch(e) { return e } } const getIngredientsOnline = () => Promise.all([ getButter(), getFlour(), getSugar(), getEggs(), ]) // boilerplate async functions that return strings const mix = async (ingredients) => `Mixing ${ingredients}` const cook = async (cakeMix) => 'Hot Cake' const stand = async (hotCake) => '🍰' const bakeACake = async () => { try { const ingredients = await getIngredientsOnline() const cakeMix = await mix(ingredients) const hotCake = await cook(cakeMix) const cake = await stand(hotCake) return cake } catch (e) { console.info(e) } } bakeACake() -
jh3y revised this gist
Dec 14, 2019 . 1 changed file with 28 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,22 @@ const PROB = 0.9 const grabIngredient = ingredient => () => { return new Promise((resolve, reject) => { setTimeout(() => { if (Math.random() > PROB) { resolve(ingredient) } else { reject(`Sorry, we've got no ${ingredient}`) } }, Math.random() * 1000) }) } // boilerplate functions for getting the different ingredients const getButter = grabIngredient('Butter') const getFlour = grabIngredient('Flour') const getSugar = grabIngredient('Sugar') const getEggs = grabIngredient('Eggs') const getIngredientsFromTheSuperMarket = async () => { try { @@ -30,16 +33,17 @@ const getIngredientsFromTheSuperMarket = async () => { } catch(e) { return e } } const getIngredientsOnline = () => { try { return Promise.all([ getButter(), getFlour(), getSugar(), getEggs(), ]) } catch (e) { console.info('Oops! ', e) } } // boilerplate async functions that return strings @@ -55,5 +59,4 @@ const bakeACake = async () => { return cake } bakeACake() -
jh3y revised this gist
Dec 14, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ const getIngredientsOnline = async () => { } // boilerplate async functions that return strings const mix = async (ingredients) => `Mixing ${ingredients}` const cook = async (cakeMix) => 'Hot Cake' const stand = async (hotCake) => '🍰' @@ -56,4 +56,4 @@ const bakeACake = async () => { } // create a fresh cake and log it in the callback const freshCake = bakeACake().then(console.info) -
jh3y created this gist
Jan 25, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ // helper function for stock check const doTheyHaveIt = () => Math.random() > 0.1 // boilerplate functions for getting the different ingredients const getButter = () => new Promise((resolve, reject) => { setTimeout(doTheyHaveIt() ? resolve('Butter') : reject('Sorry, no butter'), 1000) }) const getFlour = () => new Promise((resolve, reject) => { setTimeout(doTheyHaveIt() ? resolve('Flour') : reject('Sorry, no flour'), 1000) }) const getSugar = () => new Promise((resolve, reject) => { setTimeout(doTheyHaveIt() ? resolve('Sugar') : reject('Sorry, no sugar'), 1000) }) const getEggs = () => new Promise((resolve, reject) => { setTimeout(doTheyHaveIt() ? resolve('Eggs') : reject('Sorry, no eggs'), 1000) }) const getIngredientsFromTheSuperMarket = async () => { try { const butter = await getButter() const flour = await getFlour() const sugar = await getSugar() const eggs = await getEggs() return [ butter, flour, sugar, eggs, ] } catch(e) { return e } } const getIngredientsOnline = async () => { try { return await Promise.all([ getButter(), getFlour(), getSugar(), getEggs(), ]) } catch (e) { return e } } // boilerplate async functions that return strings const mix = async (ingredients) => 'Cake Mix' const cook = async (cakeMix) => 'Hot Cake' const stand = async (hotCake) => '🍰' const bakeACake = async () => { const ingredients = await getIngredientsOnline() const cakeMix = await mix(ingredients) const hotCake = await cook(cakeMix) const cake = await stand(hotCake) return cake } // create a fresh cake and log it in the callback const freshCake = bakeACake().then((cake) => console.info(cake))