public Producer(ThirdPartyLib.Producer p) { _stream = Observable.Create(observer => { ProducerMessageHandler h = msg => observer.OnNext(msg); var unsubscribe = Disposable.Create(() => p.Detach(h)); p.Attach(h); p.Start(); return(unsubscribe); }); }
public Producer(ThirdPartyLib.Producer p) { var c = Observable.Create(observer => { ProducerMessageHandler h = msg => observer.OnNext(msg); p.Attach(h); p.Start(); return(Disposable.Empty); }).Publish(); // Connect the observable the first time someone starts // observing _stream = Observable.Create(observer => { var subscription = c.Subscribe(observer); if (Interlocked.Exchange(ref _connected, 1) == 0) { c.Connect(); } return(subscription); }); }