What are the different techniques you can use to create instances of Async<'T> in F#?
I see there are a number of extension methods for web client/request and file stream, but if I want to write my own provider of async computations, how would I go about writing those AsyncDoSomething versions of my synchronous DoSomething functions?
I know that you can use a delegate of the same signature to wrap the original function, and then use Async.FromBeginEnd on the BeginInvoke and EndInvoke methods:
open System
let del : Func<int> = new Func<int>(fun () -> 42)
let delAsync = async {
let! res = Async.FromBeginEnd(del.BeginInvoke, del.EndInvoke)
printfn "result was %d" res
}
Async.Start delAsync
But this feels a little forced and it doesn't seem to be the 'F# way' as you have to use delegates defined in C# or VB (of which there are plenty of System.Action and System.Func variants to choose from of course) because F# delegates don't support the BeginInvoke and EndInvoke methods.
Does anyone have a list of the different ways you can write an async version of a synchronous function in F#?
Many thanks in advance!