Last active
December 12, 2021 19:55
Revisions
-
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 55 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ function chopCarrots() { let k = 0; for (let i=0; i<10000; i++) { for (let j=0; j<10000; j++) { k = Math.pow(k, i * j) / k } } console.log("Done chopping carrots!"); } function chopOnions() { let k = 0; for (let i=0; i<10000; i++) { for (let j=0; j<10000; j++) { k = Math.pow(k, i * j) / k } } console.log("Done chopping onions!"); } function addOnions() { console.log('Add Onions to pot!'); } function addCarrots() { console.log('Add Carrots to pot!'); } async function letPotKeepBoiling(time) { return new Promise((resolve) => setTimeout(() => { console.log("Pot has boiled for ", time, " minutes"); resolve(); }, time * 100)); } async function boilPot() { return new Promise((resolve) => setTimeout(() => { console.log("Done boiling pot!"); resolve(); }, 5000)); } async function makeSoup() { const pot = boilPot(); chopCarrots(); chopOnions(); await pot; addCarrots(); await letPotKeepBoiling(5); addOnions(); await letPotKeepBoiling(10); console.log("Your vegetable soup is ready!"); } makeSoup(); -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ function makeSoup() { return Promise.all([ new Promise((reject, resolve) => { chopCarrots(); chopOnions(); resolve(); }), boilPot() ]).then(() => { addCarrots(); return letPotKeepBoiling(5); }).then(() => { addOnions(); return letPotKeepBoiling(10); }) } -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ function callbackHell() { boilPot(() => { addCarrots(); letPotKeepBoiling( () => { addOnions(); letPotKeepBoiling( () => { console.log("Your vegetable soup is ready!"); }, 1000, ); }, 5000 ) }, 5000, chopCarrots(), chopOnions(), ); } -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ makeSoup(); makePasta(); -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ async function makeSoup() { const pot = boilPot(); chopCarrots(); chopOnions(); await pot; addCarrots(); await letPotKeepBoiling(5); addOnions(); await letPotKeepBoiling(10); console.log("Your vegetable soup is ready!"); } makeSoup(); -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 13 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,13 @@ function makeSoup() { const pot = boilPot(); chopCarrots(); chopOnions(); await pot; addCarrots(); await letPotKeepBoiling(5); addOnions(); await letPotKeepBoiling(10); console.log("Your vegetable soup is ready!"); } makeSoup(); -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const pot = boilPot(); chopCarrots(); chopOnions(); await pot; addCarrots(); await letPotKeepBoiling(5); addOnions(); await letPotKeepBoiling(10); console.log("Your vegetable soup is ready!"); -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ async function asyncFunction() { /* Returns a promise... */ } result = await asyncFunction(); -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ 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 */ } -
jackpordi revised this gist
Sep 3, 2019 . 2 changed files with 1 addition and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -18,12 +18,4 @@ function addOnions() { function addCarrots() { console.log('Add Carrots to pot!'); } -
jackpordi revised this gist
Sep 3, 2019 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ function chopCarrots() { /** * Some long computational task here... */ console.log("Done chopping carrots!"); } function chopOnions() { /** * Some long computational task here... */ console.log("Done chopping onions!"); } function addOnions() { console.log('Add Onions to pot!'); } function addCarrots() { console.log('Add Carrots to pot!'); } 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 */ } -
jackpordi created this gist
Sep 3, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ console.log('init');