I\'m trying to implement a pattern I read from Don Syme\'s blog
(https://blogs.msdn.microsoft.com/dsyme/2010/01/09/async-and-parallel-design-patterns-in-f-parallelizing-
@Tomas already has a great answer. I'll just say a couple bits in addition.
The idiom for F# asyncs is to name the method with an "Async" prefix (AsyncFoo
, not FooAsync
; the latter is an idiom already used by another .NET technology). So your functions should be getStockData
and asyncGetStockData
.
Inside an async workflow, whenever you use let!
instead of let
or do!
instead of do
, the thing on the right should have type Async
instead of T
. Basically you need an existing async computation in order to 'go async' at this point in the workflow. Each Async
will itself be either some other async{...}
workflow, or else an async "primitive". The primitives are defined in the F# library or created in user code via Async.FromBeginEnd
or Async.FromContinuations
which enable defining the low-level details of starting a computation, registering an I/O callback, releasing the thread, and then restarting the computation when getting called back. So you have to 'plumb' async all the way down to some truly-async-I/O-primitive in order to get the full benefits of async I/O.