6

我有一个如下的异步计算(见内联注释):

async {
  //...
  do! Async.Sleep(100) //cancellation may happen during sleep
  //... but isn't checked at the end of the sleep, so regular, non-async computations are executed here 
}

为了在达到“常规”计算部分之前强制取消检查/终止整个异步计算,我do! Async.Sleep(1)do! Async.Sleep(100). 有没有更清洁的方法来做到这一点?甚至可能是do! Async.Nop.

4

1 回答 1

5

像这样的东西怎么样:

let nop = async.Return ()

然后你可以像这样使用它:

async {
    // ...
    do! Async.Sleep 100
    do! nop
}
于 2013-09-07T20:17:49.113 回答