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.

Example

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

Implementation

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