`Observable.Create` doesn't work as expected
fuchen opened this issue · comments
fuchen commented
Description
open System
open System.Reactive.Linq
open System.Reactive.Disposables
open FSharp.Control.Reactive
open FSharp.Control.Reactive.Observable
[<EntryPoint>]
let main argv =
fun (ob: IObserver<int>) ->
ob.OnNext(1)
ob.OnNext(2)
ob.OnNext(3)
ob.OnCompleted()
fun ()-> () // Change to: `Disposable.Empty`, then everything works well
|> Observable.Create
|> Observable.subscribe (printfn "=%A")
|> ignore
0
Expected behavior
Should print:
=1
=2
=3
Actual behavior
No output
Known workarounds
Return Disposable.Empty
rather than fun ()-> ()
, then everything goes well.
Ryan Riley commented
Two options appear to present themselves:
- Remove the overloads, as they are not typically needed in current versions of F#
- Coerce the overload taking
IObserver<'T> -> unit -> unit
intoIObserver<'T> -> Disposable.Empty
If the latter works, that might be the best. You can still try to opt into the other by explicitly wrapping fun () -> ()
in Action(fun () -> ())
, but as you say, that appears to be causing problems.