I have a problem with developing a simple application in F#, which just reads the length of the requested HTML page.
Seems to be that such an error would be similar for
As an alternative to using the Invoke
operation (or context switching) explicitly, you can also start the computation using Async.StartImmediate
.
This primitive starts the asynchronous workflow on a current thread (synchronization context) and then it ensures that all continuations are called on the same synchronization context - so it essentially handles Invoke
automatically for you.
To do that, you do not need to change anything in fetchAsync
. You just need to change how the computation is started in runAll
:
let runAll() =
urlList
|> Seq.map fetchAsync
|> Async.Parallel
|> Async.Ignore
|> Async.StartImmediate
Just like before, this composes all of them in parallel, then it ignores the result to get a computation of type Async
and then it starts it on a current thread. This is one of the nice features in F# async :-)