9 Asynchronous functional programming in F#

 

This chapter covers

  • Making asynchronous computations cooperate
  • Implementing asynchronous operations in a functional style
  • Extending asynchronous workflow computational expressions
  • Taming parallelism with asynchronous operations
  • Coordinating cancellation of parallel asynchronous computations

In chapter 8, I introduced asynchronous programming as Tasks executing independently from the main application thread, possibly in a separated environment or across the network on different CPUs. This method leads to parallelism, where applications can perform an inordinately high number of I/O operations on a single-core machine. This is a powerful idea in terms of program execution and data throughput speed, casting away the traditional step-by-step programming approach. Both the F# and C# programming languages provide a slightly different, yet elegant, abstraction for expressing asynchronous computations, making them ideal tools, well suited for modeling real-world problems. In chapter 8, you saw how to use the asynchronous programming model in C#. In this chapter, we look at how to do the same in F#. This chapter helps you understand the performance semantics of the F# asynchronous workflow so you can write efficient and performant programs for processing I/O-bound operations.

9.1 Asynchronous functional aspects

9.2 What’s the F# asynchronous workflow?

9.2.1 The continuation passing style in computation expressions

9.2.2 The asynchronous workflow in action: Azure Blob storage parallel operations

9.3 Asynchronous computation expressions

9.3.1 Difference between computation expressions and monads

9.3.2 AsyncRetry: building your own computation expression

9.3.3 Extending the asynchronous workflow

9.3.4 Mapping asynchronous operation: the Async.map functor

9.3.5 Parallelize asynchronous workflows: Async.Parallel

9.3.6 Asynchronous workflow cancellation support

9.3.7 Taming parallel asynchronous operations

Summary