fsprojects / FSharpx.Extras

Functional programming and other utilities from the original "fsharpx" project
https://fsprojects.github.io/FSharpx.Extras/
The Unlicense
683 stars 146 forks source link

Updated AwaitObservable so that only one continuation is called with hot observables #317

Closed anton-pt closed 9 years ago

anton-pt commented 9 years ago

With the previous implementation of AwaitObservable, hot observables (returned from methods such as Observable.Replay) would result in multiple continuation functions being called as the observer OnNext, OnError and OnCompleted methods are sometimes called as soon as the subscription is made. Added some failing unit tests to show this behaviour and changed the implementation of AwaitObservable to pass them. The new implementation starts a finite state machine style agent internally.

The unit tests in AwaitObservableTests.fs were set to be ignored as they were previously failing erratically. The new implementation seems to fix that (they each passed 1000 repeats here) so I have re-enabled them.

exercitusvir commented 9 years ago

I just got an InvalidOperationException with the message Async.FromContinuations was invoked multiple time" when using the AwaitObservable that takes only a single IObservable in FSharpx.Async 1.12.0

Is this commit already in the nuget package of in FSharpx.Async 1.12.0?

I am calling AwaitObservable from within an Async returned by AwaitObservable that is still running. Might this be causing the problem? Are your tests covering that case?

anton-pt commented 9 years ago

Sorry, there was some issue with one of my unit tests which was causing the build server to hang or something so the PR wasn't accepted. I keep meaning to sort it out but forgetting. I'll try to do it ASAP.

exercitusvir commented 9 years ago

Your commit does actually fix my problem. Thank you so much for that!

anton-pt commented 9 years ago

@exercitusvir I have just submitted a PR to the FSharpx.Async project which contains the updated code: https://github.com/fsprojects/FSharpx.Async/pull/30 as I don't think this project is maintained anymore.