[英]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()
. TcpListener.BeginAcceptTcpClient()
和EndAcceptTcpClient()
都没有F#异步包装器(在PowerPack中EndAcceptTcpClient()
。
How do I write my own wrapper around these, so that I can use the let!
我如何围绕这些编写自己的包装,以便可以使用
let!
and async
keywords and run it in parallel? 和
async
关键字并并行运行?
Have you checked out the Async.BuildPrimitive
function? 您是否签出了
Async.BuildPrimitive
函数? 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. 创建扩展方法以返回适当的异步结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.