Observable<T>.defer constructor

Observable<T>.defer(Stream<T> streamFactory(), { bool reusable: false })

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

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

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


new Observable.defer(() => new Observable.just(1))
  .listen(print); //prints 1


factory Observable.defer(Stream<T> streamFactory(),
        {bool reusable = false}) =>
    Observable<T>(DeferStream<T>(streamFactory, reusable: reusable));