【发布时间】:2021-11-26 22:54:38
【问题描述】:
我正在编写一个异步方法,它应该异步查询端口,直到找到一个端口,或者在 5 分钟后超时;
member this.GetPort(): Async<Port> = this._GetPort(DateTime.Now)
member this._GetPort(startTime: DateTime): Async<Port> = async {
match this._TryGetOpenPort() with
| Some(port) -> port
| None -> do
if (DateTime.Now - startTime).TotalMinutes >= 5 then
raise (Exception "Unable to open a port")
else
do! Async.Sleep(100)
let! result = this._GetPort(startTime)
result}
member this._TryGetOpenPort(): Option<Port> =
// etc.
但是,我在_GetPort 中发现了一些奇怪的类型不一致;该函数说我返回的是Async<unit>而不是Async<Port>。
【问题讨论】:
标签: asynchronous types f# timeout matching