Thomas
Thomas

Reputation: 12127

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

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?

Upvotes: 3

Views: 206

Answers (1)

Brian Berns
Brian Berns

Reputation: 17153

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.

Upvotes: 2

Related Questions