Front end of the Slack clone application.

timeoutWith.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { async } from '../scheduler/async';
  2. import { timeoutWith as higherOrder } from '../operators/timeoutWith';
  3. /* tslint:enable:max-line-length */
  4. /**
  5. *
  6. * Errors if Observable does not emit a value in given time span, in case of which
  7. * subscribes to the second Observable.
  8. *
  9. * <span class="informal">It's a version of `timeout` operator that let's you specify fallback Observable.</span>
  10. *
  11. * <img src="./img/timeoutWith.png" width="100%">
  12. *
  13. * `timeoutWith` is a variation of `timeout` operator. It behaves exactly the same,
  14. * still accepting as a first argument either a number or a Date, which control - respectively -
  15. * when values of source Observable should be emitted or when it should complete.
  16. *
  17. * The only difference is that it accepts a second, required parameter. This parameter
  18. * should be an Observable which will be subscribed when source Observable fails any timeout check.
  19. * So whenever regular `timeout` would emit an error, `timeoutWith` will instead start re-emitting
  20. * values from second Observable. Note that this fallback Observable is not checked for timeouts
  21. * itself, so it can emit values and complete at arbitrary points in time. From the moment of a second
  22. * subscription, Observable returned from `timeoutWith` simply mirrors fallback stream. When that
  23. * stream completes, it completes as well.
  24. *
  25. * Scheduler, which in case of `timeout` is provided as as second argument, can be still provided
  26. * here - as a third, optional parameter. It still is used to schedule timeout checks and -
  27. * as a consequence - when second Observable will be subscribed, since subscription happens
  28. * immediately after failing check.
  29. *
  30. * @example <caption>Add fallback observable</caption>
  31. * const seconds = Rx.Observable.interval(1000);
  32. * const minutes = Rx.Observable.interval(60 * 1000);
  33. *
  34. * seconds.timeoutWith(900, minutes)
  35. * .subscribe(
  36. * value => console.log(value), // After 900ms, will start emitting `minutes`,
  37. * // since first value of `seconds` will not arrive fast enough.
  38. * err => console.log(err) // Would be called after 900ms in case of `timeout`,
  39. * // but here will never be called.
  40. * );
  41. *
  42. * @param {number|Date} due Number specifying period within which Observable must emit values
  43. * or Date specifying before when Observable should complete
  44. * @param {Observable<T>} withObservable Observable which will be subscribed if source fails timeout check.
  45. * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
  46. * @return {Observable<T>} Observable that mirrors behaviour of source or, when timeout check fails, of an Observable
  47. * passed as a second parameter.
  48. * @method timeoutWith
  49. * @owner Observable
  50. */
  51. export function timeoutWith(due, withObservable, scheduler = async) {
  52. return higherOrder(due, withObservable, scheduler)(this);
  53. }
  54. //# sourceMappingURL=timeoutWith.js.map