Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write my own async wrapper for TcpListener?

There is no F# async wrapper (in the PowerPack) for neither TcpListener.BeginAcceptTcpClient() nor EndAcceptTcpClient().

How do I write my own wrapper around these, so that I can use the let! and async keywords and run it in parallel?

like image 936
esac Avatar asked Sep 23 '09 15:09

esac


1 Answers

Have you checked out the Async.BuildPrimitive function? I think you can do something like:

type TcpListener with
  member x.AsyncAcceptClient() = 
    Async.BuildPrimitive(x.BeginAcceptTcpClient, x.EndAcceptTcpClient)

to create an extension method returning an appropriate async result.

like image 110
kvb Avatar answered Nov 15 '22 08:11

kvb