F # Reactively wait for watch to complete

I found many SO questions but couldn't find a F # solution. I need to block and wait until the event fires for me to check the returned data. I am using Rx to receive the 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 convert the results to a list so that they can be tested later using a test environment (xUnit), or wait for all three events to complete and submit Assert.True

.

How can I wait for 3 shooting events before proceeding? I see what other sources are Observable.wait

suggesting Async.RunSynchronously

.

+3


source to share


1 answer


I think the easiest option is to use a function Async.AwaitObservable

- unfortunately this is not yet available in the main F # library, but you can get it from the FSharpx.Async package, or just copy the gruce function from GitHub .

Using this function, you should write something like:



let _, data = 
  Observable.take 3 ackNack
  |> Async.AwaitObservable
  |> Async.RunSynchronously

Console.WriteLine("{0}", data.AckNack)
Assert.True(data.TotalAckCount > 0u)

      

+6


source







All Articles