diff --git a/async-await/event-loop.md b/async-await/event-loop.md new file mode 100644 index 0000000..038f10b --- /dev/null +++ b/async-await/event-loop.md @@ -0,0 +1,23 @@ +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: + +1. ```javascript + setTimeout(() => console.log('test'), 1000); + ``` +`console.log('test')` will be put in the Event Loop. + +2. ```javascript + const promise = new Promise(function (resolve, reject) { + console.log('test'); + resolve(); +}).then(() => { + console.log('test2'); +}); +``` +`console.log('test2')` will be put in the Event Loop. \ No newline at end of file diff --git a/async-await/event-loop.txt b/async-await/event-loop.txt deleted file mode 100644 index e72618e..0000000 --- a/async-await/event-loop.txt +++ /dev/null @@ -1,4 +0,0 @@ -JavaScript is single-threaded (but note that NodeJS is not entirely single-threaded, as it internally mantains a thread -pool), but it can still take advantage of asynchronous programming. - -The Event Loop, which is a JavaScript construct that completes a new task while waiting for another. \ No newline at end of file