我不理解Async.RunSynchronously
何时给出超时参数的语义。为什么以下示例不终止?
let runInMaxTime (time: int) (work: Async<'T>) =
try
Async.RunSynchronously(work,time)
|> Some
with
| _ ->
None
let rec forever () : unit =
printfn "Forever looping"
forever ()
// Never terminates
let x = runInMaxTime 10 <| async {return forever ()}
正确的实现是runInMaxTime
什么样的?我想出的唯一可行的方法是基于Task
s 和取消令牌。