43c79fba0ada5fc98d1da2fba5ff39fd255f3fd92368d869432d0dfdc9e152625294dd9e32d921af6a04779813ca3d71d287e9bf261c8fba5a377ddb91e739 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Observable } from '../Observable';
  2. import { noop } from '../util/noop';
  3. /**
  4. * An Observable that emits no items to the Observer and never completes.
  5. *
  6. * ![](never.png)
  7. *
  8. * A simple Observable that emits neither values nor errors nor the completion
  9. * notification. It can be used for testing purposes or for composing with other
  10. * Observables. Please note that by never emitting a complete notification, this
  11. * Observable keeps the subscription from being disposed automatically.
  12. * Subscriptions need to be manually disposed.
  13. *
  14. * ## Example
  15. *
  16. * Emit the number 7, then never emit anything else (not even complete)
  17. *
  18. * ```ts
  19. * import { NEVER, startWith } from 'rxjs';
  20. *
  21. * const info = () => console.log('Will not be called');
  22. *
  23. * const result = NEVER.pipe(startWith(7));
  24. * result.subscribe({
  25. * next: x => console.log(x),
  26. * error: info,
  27. * complete: info
  28. * });
  29. * ```
  30. *
  31. * @see {@link Observable}
  32. * @see {@link EMPTY}
  33. * @see {@link of}
  34. * @see {@link throwError}
  35. */
  36. export const NEVER = new Observable<never>(noop);
  37. /**
  38. * @deprecated Replaced with the {@link NEVER} constant. Will be removed in v8.
  39. */
  40. export function never() {
  41. return NEVER;
  42. }