Snippets

Tuomas Hietanen Async computation with cancellation timeout

Created by Tuomas Hietanen
1
2
3
4
5
6
7
8
9
//Add timeout to async module.
module Async =
  /// Async.Start with timeout in seconds
  let StartWithTimeout (timeoutSecs:int) (computation:Async<unit>) =
    let c = new System.Threading.CancellationTokenSource(timeoutSecs*1000)
    Async.Start(computation, cancellationToken = c.Token)

// Another way to setup timeout to existing async computation would be:
// Async.StartChild(myComputation(), timeout)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.