[Перевод] Async/Await в C# это синтаксический сахар для конечного автомата
Перевод статьи, посвящённой устройству конечного автомата асинхронных методов. Разбор основных понятий, декомпилированный код с подробными комментариями, раскрытие секретов магии асинхронности и подробная схема.
https://habr.com/ru/articles/1035442/
#асинхронность #async #await #c# #конечный_автомат #awaiter #c#net #taskbuilder #statemachine
ClojureScript Gets Async/Await
https://clojurescript.org/news/2026-05-07-release
#HackerNews #ClojureScript #Async #Await #FunctionalProgramming #JavaScript #News #Development

await doesn't create a new thread. It never did. Here's what actually happens under the hood: 𝟏. 𝐓𝐡𝐞 𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐫 𝐫𝐞𝐰𝐫𝐢𝐭𝐞𝐬 𝐲𝐨𝐮𝐫 𝐦𝐞𝐭𝐡𝐨𝐝 → Your async method becomes a state machine struct → Implements IAsyncStateMachine with a MoveNext() method → Each "await" becomes a pause point between states 𝟐. 𝐖𝐡𝐚𝐭 𝐡𝐚𝐩𝐩𝐞𝐧𝐬 𝐚𝐭 "𝐚𝐰𝐚𝐢𝐭" → The task is checked. If already completed, execution continues immediately. → If not, a continuation callback is registered → The current thread is released back to the thread pool → No thread is blocked. None. 𝟑. 𝐖𝐡𝐞𝐧 𝐭𝐡𝐞 𝐭𝐚𝐬𝐤 𝐜𝐨𝐦𝐩𝐥𝐞𝐭𝐞𝐬 → The continuation fires → MoveNext() is called again → The state machine picks up where it left off on a thread pool thread 𝟒. 𝐒𝐲𝐧𝐜𝐡𝐫𝐨𝐧𝐢𝐳𝐚𝐭𝐢𝐨𝐧𝐂𝐨𝐧𝐭𝐞𝐱𝐭 → ASP .NET Core: none. Continuations resume on any thread pool thread. → WPF/WinForms: captures the UI thread. This is where deadlocks happen. 𝟓. 𝐚𝐰𝐚𝐢𝐭 𝐝𝐨𝐞𝐬 𝐍𝐎𝐓 𝐜𝐫𝐞𝐚𝐭𝐞 𝐚 𝐧𝐞𝐰 𝐭𝐡𝐫𝐞𝐚𝐝 → It releases the current one. That's it. → This is the most common misconception about async in C#. 𝟑 𝐭𝐫𝐚𝐩𝐬 𝐭𝐡𝐚𝐭 𝐤𝐞𝐞𝐩 𝐬𝐡𝐨𝐰𝐢𝐧𝐠 𝐮𝐩: ❌ Calling .Result or .Wait() on a Task. Blocks the thread and risks deadlocks. ❌ Using async void (except for event handlers). Exceptions crash the process. ❌ Forgetting ConfigureAwait(false) in library code. Causes subtle context issues. I made a free .NET Interview Prep guide covering the questions senior devs actually get asked 👇 https://lnkd.in/g9bWNzkR | 31 comments on LinkedIn