I am trying to learn how async
and let!
work in F#.
All the docs i\'ve read seem confusing.
What\'s the point of running an async block with Async
The idea behind let!
and Async.RunSynchronously
is that sometimes you have an asynchronous activity that you need the results of before you can continue. For example, the "download a web page" function may not have a synchronous equivalent, so you need some way to run it synchronously. Or if you have an Async.Parallel
, you may have hundreds of tasks all happening concurrently, but you want them all to complete before continuing.
As far as I can tell, the reason you would use Async.StartImmediate
is that you have some computation that you need to run on the current thread (perhaps a UI thread) without blocking it. Does it use coroutines? I guess you could call it that, although there isn't a general coroutine mechanism in .Net.
So why does Async.Parallel
require a sequence of Async<'T>
? Probably because it's a way of composing Async<'T>
objects. You could easily create your own abstraction that works with just plain functions (or a combination of plain functions and Async
s, but it would just be a convenience function.