This chapter covers
- Understanding the importance of asynchronous code
- Writing asynchronous code in C#
- Bridging .NET asynchronous code to Rx
- Creating observables of periodic behaviors
If there’s one thing I really dislike, it’s standing in line, especially a long line. I always feel I’m wasting time that I could invest in other things (such as writing a book). I always love the restaurants that allow you to come in and leave your name for a seat, which then frees you to walk around, admire the view, shop, and so forth. When your seat is available, or when your time slot arrives, you’re notified by a phone call or buzzer. For me, this is customer service at its best.
Like you and me, our code sometimes needs to stand in line and wait for something; this is what we call the synchronous way. Like you and me, our code can be notified when a task is complete and can harvest the result; this is the asynchronous way. Writing asynchronous code is crucial for modern apps to be responsive (and react in a timely manner) and it’s a key trait for being reactive. In this chapter, you’ll look at patterns for executing code asynchronously in .NET and see how they relate to your observables. You’ll look at ways to create observables from asynchronous types and learn about obstacles you might face when doing so.