Node.js vs Async/await in .net

前端 未结 4 1254
野的像风
野的像风 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:36

    The difference between Node.js's async model and C#'s async/await model is huge. The async model that has Node.js is similar to the old async model in C# and .Net called Event-based Asynchronous Pattern (EAP). C# and .Net has 3 async models, you can read about them at Asynchronous Programming Patterns. The most modern async model in C# is Task-based with C#'s async and await keywords, you can read about it at Task-based Asynchronous Pattern. The C#'s async/await keywords make asynchronous code linear and let you avoid "Callback Hell" much better then in any of other programming languages. You need just try it, and after that you will never do it in other way. You just write code consuming asynchronous operations and don't worry about readability because it looks like you write any other code. Please, watch this videos:

    1. Async programming deep dive
    2. Async in ASP.NET
    3. Understanding async and Awaitable Tasks

    And please, try to do something asynchronous in both C# and then Node.js to compare. You will see the difference.

    EDIT: Since Node.js V8 JavaScript engine supports generators, defined in ECMAScript 6 Draft, "Callback Hell" in JavaScript code also can be easily avoided. It brings some form of async/await to life in JavaScript

提交回复
热议问题