Last active
July 17, 2020 02:38
-
-
Save solanoepalacio/26e60253afaf793615ef2ad115a45903 to your computer and use it in GitHub Desktop.
Revisions
-
solanoepalacio revised this gist
Jul 17, 2020 . 1 changed file with 2 additions and 0 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 @@ -25,7 +25,9 @@ new Promise((resolve) => { 1 + 1 // nothing, really... } }); let timeoutScheduled = Date.now(); setTimeout(() => { const delay = Date.now() - timeoutScheduled; -
solanoepalacio revised this gist
Jul 17, 2020 . 1 changed file with 1 addition 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 @@ -9,11 +9,11 @@ const { spawn } = require('child_process'); // Create a task that takes 95ms to complete new Promise((resolve) => { console.time('sleep'); spawn('sleep', ['0.085']).on('close', () => { console.log('closed'); console.timeEnd('sleep'); resolve(); }); }).then(() => { @@ -27,7 +27,6 @@ new Promise((resolve) => { }); let timeoutScheduled = Date.now(); setTimeout(() => { const delay = Date.now() - timeoutScheduled; console.log(`${delay} ms have passed since I was scheduled`); -
solanoepalacio created this gist
Jul 17, 2020 .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,36 @@ /** * Shows how the event loop can be delayed to the execution of a timer. * inspired on node-js docs example: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/ */ 'use-strict'; const { spawn } = require('child_process'); // Create a task that takes 95ms to complete new Promise((resolve) => { console.time('sleep'); spawn('sleep', ['0.085']).on('close', () => { console.log('closed'); console.timeEnd('sleep'); resolve(); }); }).then(() => { console.log('then'); // block the thread for 10s const startCallback = Date.now(); while (Date.now() - startCallback < 10) { 1 + 1 // nothing, really... } }); let timeoutScheduled = Date.now(); setTimeout(() => { const delay = Date.now() - timeoutScheduled; console.log(`${delay} ms have passed since I was scheduled`); }, 100); 'done'