how to wait on a cancellation token AND an EventWaitHandle at the same time, in F#?

Viewed 61

I would like to find a way to combine these two lines:

cancellationToken.WaitHandle.WaitOne() |> ignore
waitHandle.WaitOne() |> ignore

whichever happens first would let the execution flow continue. Can this be done?

1 Answers

I assume you could put the the two handles in an array and then wait on it. Something like:

[|
    cancellationToken.WaitHandle
    waitHandle
|] |> WaitHandle.WaitAny |> ignore

Note: I have not tried to compile or run this code.

Related