4 ms·
One reason Erlang can do this is by having a preemptive scheduler. [1] In a single threaded language like JavaScript, if something blocks for 1 second, nothing
by PopeDotNinja 8y ago
One reason Erlang can do this is by having a preemptive scheduler. [1] In a single threaded language like JavaScript, if something blocks for 1 second, nothing else happens for 1 second. In Elixir, you can have N things that each block for 1 second, and have them all still complete in one second, even if you are running on a single core.
[1] https://en.wikipedia.org/wiki/Preemption_(computing) https://en.wikipedia.org/wiki/Preemption_(computing)
- vasilakisfil 8y agoNot really valid. In JS if a function blocks for 1 sec, the scheduler executes another function. The whole thread blocks for 1 sec only when all its async based functions block. The concurrency model is based on the event loop: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#Never_blocking https://developer.mozilla.org/en-US/docs/Web/JavaScript/Even...
- PopeDotNinja 8y agoNot all JavaScript code is async. If you write an infinite loop what takes a while, you'll lock up your entire JavaScript thread... let count = 0 ; while (count < 1000000000) { count += 1 } Counting from 1 to a billion will block any other operation from happening. In Elixir, that's not the case. Or am missing something?