I found a variety of SO questions on this but couldn't figure out an F# solution. I need to block wait for an event to fire at me to check the data it returns. I am using Rx to receive event 3 times:
let disposable =
Observable.take 3 ackNack
|> Observable.subscribe (
fun (sender, data) ->
Console.WriteLine("{0}", data.AckNack)
Assert.True(data.TotalAckCount > 0u)
)
I would like to either turn results into a list, so they can be checked later on by the test framework (xUnit), or wait for all 3 events to complete and pass the Assert.True
.
How would I wait for 3 events to fire before continuing? I can see there's an Observable.wait
other sources suggest Async.RunSynchronously
.
I think the easiest option is to use Async.AwaitObservable
function - sadly, this is not yet available in the F# core library, but you can get it from the FSharpx.Async package, or just copy the function soruce from GitHub.
Using the function, you should be able to write something like:
let _, data =
Observable.take 3 ackNack
|> Async.AwaitObservable
|> Async.RunSynchronously
Console.WriteLine("{0}", data.AckNack)
Assert.True(data.TotalAckCount > 0u)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With