Real advantages of Async-Await?

后端 未结 1 1877
别那么骄傲
别那么骄傲 2020-12-06 13:24

Earlier i\'ve posted this question related to applying Async-Await at client or at service. Do read the question before going ahead with this question as it is tightly coupl

相关标签:
1条回答
  • 2020-12-06 14:00

    Client-side async (compared to synchronous code) generally improves responsiveness at a slight cost of memory.

    Server-side async (compared to synchronous code) generally improves scalability by reducing memory/thread usage. These advantages also apply to client-side async (compared to multithreaded code).

    Both of these are extreme generalizations and there are certainly situations where they're wrong.

    Update:

    My observation concludes that if we use Async-Await ..., then it will consume lesser threads.

    async / await enable maintainable asynchronous code. By themselves, they don't have anything to do with creating threads. However, they are often used with Task.Run (or Task.Factory.StartNew) to create background tasks.

    As i am learning async - await, i want to prove its worth by some sort of comparison and solid code.

    async and await are compiler transformations. They make it easier to write asynchronous programs - that is all.

    If you compare them to synchronous code, then you'll usually see improved responsiveness and/or scalability. If you compare them to existing asynchronous code, then they'll usually be slightly less efficient but more than make up for that in terms of code maintainability.

    0 讨论(0)
提交回复
热议问题