CodeMash 2024 – Async/Await from the Ground Up

I was excited to see that Stephen Cleary had sessions at CodeMash. He’s one of the C# Advent carolers! The younger Sadukelet said “Mama – that was 4 Async Tasks?!” 😁 Yes, sir, 4 Async Tasks is speaking at CodeMash.

Whenever I see Stephen’s name on a conference line-up, I know that there are going to be some deep or harder topics presented and in a way that the average developer can understand it. Stephen takes complex topics and demystifies them. When I saw async and await, I had to see what this was about – as I’ve been dealing with async stuff since the late 90s, in the wee days of AJAX calls. So it’s been fun watching async evolve!

There Is No Thread

While talking about asynchronous, the phrases of concurrency, multithreaded, and parallel came up. Then, there were talks of threads. However, when dealing with asynchrony, we’re looking at concurrency without threads. Wait… no threads?! Stephen has a blog post from 2013 that is still relevant today: There Is No Thread. 🤯

Async/Await in C#

We officially got async in C# as part of .NET 5. Stephen recommended Jon Skeet’s Eduasync series as a guide for when we aren’t at the talk. During the talk, though, Stephen talked of how async turns a method into a state machine and enables the await keyword. He also mentioned that it is similar to how a yield works. With regards to Task in C#, it is nothing more than an object that represent the execution of an async method without a return result. Task<TResult> represents the execution with a return result.

The Archaelogy of Async 👵🏻

It was this part of Stephen’s talk that I felt old. He talked about the history of async. Check this out:

History of Async - Events, Callbacks, Futures, and Async/Await

This got me thinking. With Events and event-driven development, this made me think of some of the things we did in our WebForms days.

With Callbacks, I think back to AJAX in JavaScript – introduced in 2005! (Hey – at least it’s newer than “the 19’s”, as my kids put it.) When a method is done executing, then it calls back to the callback function.

Futures refers to Task<T> in C# and Promises in JavaScript. These could be used for things such as file downloads, timeouts, database writes, and more. Futures typically have some kind of state associated with their execution – such as Successful, Faulted, and Cancelled. In C#, there are Task, Task<TResult>, ValueTask, and ValueTask<TResult>.

With JavaScript, there are Promise Tasks and Delegate Tasks. Promises are run asynchronously, whereas delegates are run in parallel.

And Async/Await is where we are today with asynchronous execution. Did you know “await” is “asynchronous wait”? The things I learned in this session!

And the A/V went 💥

During the rest of the presentation, Stephen’s A/V went out. Rather than stumble through A/V debugging, Stephen continued the talk without his slides. He handled it gracefully and masterfully.

I wish I could’ve stayed to see how it ended. Unfortunately, I had to step out to deal with another community issue. However, if you ever need to try to understand async/await and have an opportunity to catch this session, do it!

By sadukie

One thought on “CodeMash 2024 – Async/Await from the Ground Up”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.