{% if book.isPdf %}
{% else %}
{% endif %}
Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.
observableFactory
(Function
): Observable factory function to invoke for each observer that subscribes to the resulting sequence.
(Observable
): An observable sequence whose observers trigger an invocation of the given observable factory function.
{% if book.isPdf %}
/* Using an observable sequence */
var source = Rx.Observable.defer(() => Rx.Observable.return(42));
var subscription = source.subscribe(
x => console.log(`onNext: ${x}`),
e => console.log(`onError: ${e}`),
() => console.log('onCompleted'));
// => onNext: 42
// => onCompleted
/* Using a promise */
var source = Rx.Observable.defer(() => RSVP.Promise.resolve(42));
var subscription = source.subscribe(
x => console.log(`onNext: ${x}`),
e => console.log(`onError: ${e}`),
() => console.log('onCompleted'));
// => onNext: 42
// => onCompleted
{% else %}
{% endif %}