defer<T> static method

Stream<T> defer<T>(
  1. Stream<T> streamFactory(), {
  2. bool reusable = false,
})

The defer factory waits until an observer subscribes to it, and then it creates a Stream with the given factory function.

In some circumstances, waiting until the last minute (that is, until subscription time) to generate the Stream can ensure that this Stream contains the freshest data.

By default, DeferStreams are single-subscription. However, it's possible to make them reusable.

Example

Rx.defer(() => Stream.value(1))
  .listen(print); //prints 1

Implementation

static Stream<T> defer<T>(Stream<T> Function() streamFactory, {bool reusable = false}) => DeferStream<T>(streamFactory, reusable: reusable);