a zip code crypto-currency system good for red ONLY

observeOn.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { observeOn as higherOrder } from '../operators/observeOn';
  2. /**
  3. *
  4. * Re-emits all notifications from source Observable with specified scheduler.
  5. *
  6. * <span class="informal">Ensure a specific scheduler is used, from outside of an Observable.</span>
  7. *
  8. * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule
  9. * notifications emitted by the source Observable. It might be useful, if you do not have control over
  10. * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.
  11. *
  12. * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,
  13. * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal
  14. * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits
  15. * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.
  16. * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split
  17. * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source
  18. * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a
  19. * little bit more, to ensure that they are emitted at expected moments.
  20. *
  21. * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications
  22. * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`
  23. * will delay all notifications - including error notifications - while `delay` will pass through error
  24. * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator
  25. * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used
  26. * for notification emissions in general.
  27. *
  28. * @example <caption>Ensure values in subscribe are called just before browser repaint.</caption>
  29. * const intervals = Rx.Observable.interval(10); // Intervals are scheduled
  30. * // with async scheduler by default...
  31. *
  32. * intervals
  33. * .observeOn(Rx.Scheduler.animationFrame) // ...but we will observe on animationFrame
  34. * .subscribe(val => { // scheduler to ensure smooth animation.
  35. * someDiv.style.height = val + 'px';
  36. * });
  37. *
  38. * @see {@link delay}
  39. *
  40. * @param {IScheduler} scheduler Scheduler that will be used to reschedule notifications from source Observable.
  41. * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.
  42. * @return {Observable<T>} Observable that emits the same notifications as the source Observable,
  43. * but with provided scheduler.
  44. *
  45. * @method observeOn
  46. * @owner Observable
  47. */
  48. export function observeOn(scheduler, delay = 0) {
  49. return higherOrder(scheduler, delay)(this);
  50. }
  51. //# sourceMappingURL=observeOn.js.map