fsprojects / FSharp.Control.Reactive

Extensions and wrappers for using Reactive Extensions (Rx) with F#.

Home Page:http://fsprojects.github.io/FSharp.Control.Reactive

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Observable.Create` doesn't work as expected

fuchen opened this issue · comments

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.

Two options appear to present themselves:

  1. Remove the overloads, as they are not typically needed in current versions of F#
  2. Coerce the overload taking IObserver<'T> -> unit -> unit into IObserver<'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.