Skip to content

Latest commit

 

History

History
67 lines (40 loc) · 1.56 KB

File metadata and controls

67 lines (40 loc) · 1.56 KB

{% if book.isPdf %}

defer

{% else %}

{% endif %}

Returns an observable sequence that invokes the specified factory function whenever a new observer subscribes.

Arguments

  1. observableFactory (Function): Observable factory function to invoke for each observer that subscribes to the resulting sequence.

Returns

(Observable): An observable sequence whose observers trigger an invocation of the given observable factory function.

Example

{% 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 %}

Using an observable sequence

Using a promise

{% endif %}