I've reviewed async
and await
in C# in some detail in the past, including reviewing all of the StackOverflow questions I've found on the topic, however I have never implemented async
and await
in code, for the following reasons:
- My understanding of the main performance benefit is if you have a long running process, followed by logic that is time-consuming to perform, followed by consumption of something returned by the first long-running process. I've never encountered this scenario. I've encountered scenarios where there is minimal logic between an initial long running process and something that relies on the long running process, and it's not compelling enough to introduce
await
andasync
for a minor performance saving. Introducing an async call introduces a small degree of complexity in terms of the order of execution, and for small performance gains I've always felt that this complexity isn't worth it - It only makes async code easier to write, and I'm usually doing all my async stuff with JavaScript (typically Angular) at the front-end, so I've never recognised a compelling need for async work at the back end
I'm often asked at job interviews about my understanding of async
and await
, and I can answer the question OK, however I've never fully comprehended or witnessed a case where async
and await
is a clearly preferable pattern in a piece of code. As I'm not in the habit of using async
and await
, I want to be able to recognise when a use case or scenario is calling out for the use of async
and await
. What is a good practical example of a compelling use case or scenario that is commonly implemented in a system?