Node.js vs Async/await in .net

前端 未结 4 1255
野的像风
野的像风 2021-01-30 12:42

Can someone explain/ redirect me, what is the difference between Node.js\'s async model(non blocking thread) vs any other language for example c#\'s asynchronous way of handling

4条回答
  •  遇见更好的自我
    2021-01-30 13:28

    With nodejs, all requests go in the event queue. Node's event loop uses a single thread to process items in the event queue, doing all non-IO work, and sending to C++ threadpool (using javascript callbacks to manage asynchrony) all IO-bound work. The C++ threads then add to the event queue its results.

    The differences with ASP.NET (the two first apply pretty much to all web servers that allow async IO) is that :

    1. ASP.NET uses a different thread for each incoming requests, so you get an overhead of context switching
    2. .NET doesn't force you to use async to do IO-bound work, so it isn't as idiomatic as nodejs where IO-bound api calls are de facto async (with callbacks)
    3. .NET' "await-async" add's a step at compile time to add "callbacks", so you can write linear code (no callback function passing), in contrast with nodejs

    There are so much places on the web that describe node's architecture, but here's something : http://johanndutoit.net/presentations/2013/02/gdg-capetown-nodejs-workshop-23-feb-2013/index.html#1

提交回复
热议问题