I don't understand the semantics of Async.RunSynchronously
when given a timeout argument. Why doesn't the following example terminate?
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 ()}
What would a proper implementation of runInMaxTime
look like? The only thing I've come up with that works is based on Task
s and cancellation tokens.