NeverObservable.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Observable } from '../Observable';
  2. import { noop } from '../util/noop';
  3. /**
  4. * We need this JSDoc comment for affecting ESDoc.
  5. * @extends {Ignored}
  6. * @hide true
  7. */
  8. export class NeverObservable extends Observable {
  9. constructor() {
  10. super();
  11. }
  12. /**
  13. * Creates an Observable that emits no items to the Observer.
  14. *
  15. * <span class="informal">An Observable that never emits anything.</span>
  16. *
  17. * <img src="./img/never.png" width="100%">
  18. *
  19. * This static operator is useful for creating a simple Observable that emits
  20. * neither values nor errors nor the completion notification. It can be used
  21. * for testing purposes or for composing with other Observables. Please note
  22. * that by never emitting a complete notification, this Observable keeps the
  23. * subscription from being disposed automatically. Subscriptions need to be
  24. * manually disposed.
  25. *
  26. * @example <caption>Emit the number 7, then never emit anything else (not even complete).</caption>
  27. * function info() {
  28. * console.log('Will not be called');
  29. * }
  30. * var result = Rx.Observable.never().startWith(7);
  31. * result.subscribe(x => console.log(x), info, info);
  32. *
  33. * @see {@link create}
  34. * @see {@link empty}
  35. * @see {@link of}
  36. * @see {@link throw}
  37. *
  38. * @return {Observable} A "never" Observable: never emits anything.
  39. * @static true
  40. * @name never
  41. * @owner Observable
  42. */
  43. static create() {
  44. return new NeverObservable();
  45. }
  46. /** @deprecated internal use only */ _subscribe(subscriber) {
  47. noop();
  48. }
  49. }
  50. //# sourceMappingURL=NeverObservable.js.map