O'Reilly logo

Programming Reactive Extensions and LINQ by Paul Betts, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Multicast, Publish and IConnectableObservable

Rx operators do not themselves have side effects, but at times, using an Rx object will have a side effect. For example, if we create an IObservable with a COM object, when we subscribe we may add a COM addref, and when we unsubscribe we might end up releasing that COM object. Worse, the effect is different if we have two subscribers than if we have one.

This problem can be eliminated using the Multicast and Publish methods. These methods return a a Connectable Observable that shares a subscription to the underlying source.

The following example demonstrates how side effects can sneak into even a simple program. It uses a Hot Observable (remember, that's a single event-stream), with explicit, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required