I'm trying to figure out how to use the Observable.create function in the FSharp.Control.Reactive library but seem to be missing something.
The function signature is defined as:
((IObserver<'a> -> unit -> unit) -> IObservable<'a>)
I've tried a few different ways of creating the observable such as:
Observable.create (fun obs -> fun _ -> obs.OnNext("xxx") )
|> Observable.subscribe (fun x -> printfn "%A" x)
and
Observable.create (fun obs -> obs.OnNext("xxx"); fun _ -> () )
|> Observable.subscribe (fun x -> printfn "%A" x)
Which compiles but doesn't ever execute the OnNext so the printfn statement in the subscribe isn't called.
I can call the Observable.Create method directly from the System.Reactive.Linq namespace as follows:
Observable.Create(fun (obs : IObserver<string>) -> obs.OnNext("www"); Action( fun _ -> () ) )
|> Observable.subscribe (fun x -> printfn "%A" x)
And this will print "www" to the interactive. Likewise, I can use the Observable.createWithDisposable as follows:
Observable.createWithDisposable(fun obs -> obs.OnNext("yyy") ; Disposable.Empty )
|> Observable.subscribe (fun x -> printfn "%A" x)
And sending this to interactive prints "yyy"
So it is just the FSharp.Control.Reactive.Observable.create that I am having trouble with.
I've had a look but can't find any examples on how this should be called so any help would be appreciated.
Thanks