JS: Concurrancy and Event Loop

Event Loop

JavaScript has a concurrency model based on an "event loop". The event loop got its name because of how it's usually implemented, which usually resembles:

while (queue.waitForMessage()) {
  queue.processNextMessage();
}

queue.waitForMessage() waits synchronously for a message to arrive if there is none currently.

  1. Each message is processed completely before any other message is processed.
  2. setTimeout message: a minimum time and not a guaranteed time.
  3. A web worker or a cross-origin iframe has its own stack, heap, and message queue. 
  4. A very interesting property of the event loop model is that JavaScript, unlike a lot of other languages, never blocks. Handling I/O is typically performed via events and callbacks

Node JS Architecture – Single Threaded Event Loop

  • The first basic thesis of node.js is that I/O is expensive.
  • The second basic thesis is that thread-per-connection is memory-expensive.
  • There is no way of making code run in parallel within a single request. However, all I/O is evented and asynchronous.
  •  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值