publishValueNotReplay method

NotReplayValueConnectableStream<T> publishValueNotReplay(
  1. T seedValue, {
  2. bool sync = true,
})

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

This is useful for converting a single-subscription stream into a broadcast Stream and provides synchronous access to the latest emitted value.

Example

final source = Stream.fromIterable([1, 2, 3]);
final connectable = source.publishValueNotReplay(0, sync: true);

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

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

await subscription.asFuture<void>();
print(connectable.value); // prints 3

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

Implementation

NotReplayValueConnectableStream<T> publishValueNotReplay(T seedValue,
        {bool sync = true}) =>
    NotReplayValueConnectableStream(this, seedValue, sync: sync);