views:

178

answers:

1

There is no F# async wrapper (in the PowerPack) for TcpListener.BeginAcceptTcpClient()/EndAcceptTcpClient(). How do I write my own wrapper around this so that I can use the let! and async keywords and run it in parallel?

+3  A: 

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.

kvb
Thanks, exactly what I was looking for
esac