publish method

ConnectableObservable<T> publish ()

Convert the current Observable into a ConnectableObservable that can be listened to multiple times. It will not begin emitting items from the original Observable until the connect method is invoked.

This is useful for converting a single-subscription stream into a broadcast Stream.

Example

final source = Observable.fromIterable([1, 2, 3]);
final connectable = source.publish();

// Does not print anything at first
connectable.listen(print);

// Start listening to the source Observable. Will cause the previous
// line to start printing 1, 2, 3
final subscription = connectable.connect();

// Stop emitting items from the source stream and close the underlying
// Subject
subscription.cancel();

Implementation

ConnectableObservable<T> publish() => PublishConnectableObservable<T>(this);