F# – helper functions to convert between Async<unit> and Task

With the offi­cial release of .Net 4.5 and Visu­al Stu­dio 2012, I sus­pect many .Net devel­op­ers will be rush­ing to rewrite their data access or net­work lay­ers (amongst many many oth­er things!) to take advan­tage of the new async-await (see the excel­lent 101 exam­ples here) lan­guage fea­ture in C#, which means you’ll like­ly be work­ing with the Task and Task<T> type an awful lot.

If you have F# code that needs to interop with C# that returns or awaits some task types then you’ve prob­a­bly already come across the Async.StartAsTask<T> and Async.AwaitTask<T> meth­ods for con­vert­ing between F#’s Async<T> and Task<T> types. Curi­ous­ly, there are no equiv­a­lent meth­ods on the Async class for con­vert­ing between Async<unit> and Task types.

So, to fill in the gaps our­selves, here are two sim­ple func­tions to do just that:



Liked this post? Why not support me on Patreon and help me get rid of the ads!