5/7/2023 0 Comments For loop as timer java![]() ![]() it executes its code in more than one thread at the same time ![]() When the blocking code finishes running, it queue’s the result of the blocking operations and pushes them back to the stack.īut JavaScript has a single thread? What then executes this blocking code while letting other codes in the thread get executed?īefore we proceed, let’s have a recap of the above. The blocking code keeps running without blocking the main execution thread. When there is a blocking operation, the event is started. Okay, things are getting really weird now, how can JavaScript be single-threaded and be concurrent at the same time? i.e., executing its code with more than one thread? AsynchronousĪsynchronous programming means that the code runs in an event loop. ConcurrentĬoncurrency means that the code is being executed concurrently by more than one thread. So non-blocking means things that aren’t slow on the thread.īut wait, did I say JavaScript runs on a single thread? And I also said it non-blocking, which means task run quickly on the call stack? But how? How about when we run timers? Loops? There is no one definition of blocking it just simply means things that are running slowly on the thread. How can JavaScript be single-threaded and non-blocking at the same time?īut what does blocking mean? Non-blocking Unlike multi-threaded languages where multiple processes can be run on several threads concurrently without blocking each other. This means it would execute an entire process from start to end without the thread being interrupted or stopped. A programming language is single-threaded means it can only perform one task or operation at a single time. Single threadĪ thread of execution is the smallest sequence of programmed instruction that can be managed independently by a scheduler. The keywords here as regards this article are single-threaded, non-blocking, concurrent, and asynchronous. Wait, what’s this? A bookish definition? □ ![]() JavaScript is an high level, interpreted, single threaded non-blocking, asynchronous, concurrent language. What really is JavaScript? We could define JavaScript as The Event Loopīefore we can understand how the event loop works, we first have to understand what JavaScript itself is and how it works! What is JavaScript?īefore we proceed, I’d like us to take a step back to the very basics. Writing asynchronous code can not be avoided in JavaScript, but why does a code running asynchronously really mean? i.e. This article focuses on one of the very important but seldom understood concepts or terms in JavaScript. It helps us make more informed decisions, which can, in turn, boost our code performance drastically. They just don’t care about understanding the complexities that have deeply abstracted from them by the language.Īs a JavaScript developer, it becomes increasingly important to understand what really happens under the hood and how most of these complexities abstracted from us really work. While it might require an in-depth understanding of languages like C++ and C to write full-scale production code, JavaScript can often be written with just a basic understanding of what can be done with the language.Ĭoncepts, like passing callbacks to functions or writing asynchronous code, are often not so difficult to implement, which makes most JavaScript developers care less about what goes on under the hood. ![]()
0 Comments
Leave a Reply. |