From 52562f6f1eef0221701fc396d3983e674e145ed5 Mon Sep 17 00:00:00 2001 From: xfarrow <49845537+xfarrow@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:52:59 +0200 Subject: [PATCH] Update event-loop.md --- async-await/event-loop.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/async-await/event-loop.md b/async-await/event-loop.md index 9ea0e8d..63f14ae 100644 --- a/async-await/event-loop.md +++ b/async-await/event-loop.md @@ -1,27 +1,29 @@ +# The Event Loop + JavaScript is single-threaded but it can still take advantage of asynchronous programming. -The Event Loop is a Javascript construct responsible -for holding operations to be executed asynchronously with respect to the main -flow of execution. Whenever we meet a portion of code that may not be -possible to execute now, it is put in the Event Loop. Let's look at some -examples: +In order to do that, the runtime keeps a structure called The Event Loop which +is responsible for holding operations to be executed asynchronously with +respect to the main flow of execution. Whenever we meet a portion of code that +may not be possible to execute now, it is put in the Event Loop. Let's look at +some examples: -1. +1. ```javascript - setTimeout(() => console.log('test'), 1000); +setTimeout(() => console.log('test'), 1000); ``` `console.log('test')` will be put in the Event Loop. -2. +2. ```javascript - const promise = new Promise(function (resolve, reject) { - console.log('test'); - resolve(); +const promise = new Promise(function (resolve, reject) { +console.log('test'); +resolve(); }).then(() => { - console.log('test2'); +console.log('test2'); }); ``` -`console.log('test2')` will be put in the Event Loop. \ No newline at end of file +`console.log('test2')` will be put in the Event Loop. \ No newline at end of file