Rx.Notification.prototype.toObservable([scheduler])

Returns an observable sequence with a single notification.

参数

  1. [scheduler = Rx.Scheduler.immediate] (Scheduler): Scheduler to send out the notification calls on.

返回值

(Observable): The observable sequence that surfaces the behavior of the notification upon subscription.

Without a scheduler
var source = Rx.Notification.createOnNext(42)
    .toObservable();

var subscription = source.subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: 42
// => onCompleted
With a scheduler
var source = Rx.Notification.createOnError(new Error('error!'))
    .toObservable(Rx.Scheduler.timeout);

var subscription = source.subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onError: Error: error!