I have to make several calls to an API over the network.
let RestCall1 args = async{ Thread.Sleep (1000); return args}
let RestCall2 args = async{Thread.Sleep (1000); return args}
I know that an async{...} context has a performance hit, so I'm trying to minimize the number of contexts I create. Plus it's awkward to pipeline.
let nested4 args = async{ let! x = RestCall1 args; return args }
let nested7 args = async{ let! x = RestCall2 args; return args }
let outerAsync (args : string) =
async {
let args1 = args
|> nested1
|> nested2
|> nested3
let! args2 = nested4 args1
let args3 = args2
|> nested5
|> nested6
return nested7 args3
}
Is there a way of doing it (like the sample below) without blocking the thread with RunSynch?
let nested4 args = RestCall1 args |> Async.RunSynchronously
let nested7 args = RestCall2 args |> Async.RunSynchronously
let outerAsync (args : string) =
async {
return
args
|> nested1
|> nested2
|> nested3
|> nested4
|> nested5
|> nested6
|> nested7
}