fb5d68bce5c9fe25e9fceead4f27e6e30ee4c8890295c4a6de247df6f1841975afdb7a3eb105f2242fa2ffe0b160c0364b7dae3cbbed51c59e9dcde6a098dd 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
  2. /**
  3. * Asynchronously subscribes Observers to this Observable on the specified {@link SchedulerLike}.
  4. *
  5. * With `subscribeOn` you can decide what type of scheduler a specific Observable will be using when it is subscribed to.
  6. *
  7. * Schedulers control the speed and order of emissions to observers from an Observable stream.
  8. *
  9. * ![](subscribeOn.png)
  10. *
  11. * ## Example
  12. *
  13. * Given the following code:
  14. *
  15. * ```ts
  16. * import { of, merge } from 'rxjs';
  17. *
  18. * const a = of(1, 2, 3);
  19. * const b = of(4, 5, 6);
  20. *
  21. * merge(a, b).subscribe(console.log);
  22. *
  23. * // Outputs
  24. * // 1
  25. * // 2
  26. * // 3
  27. * // 4
  28. * // 5
  29. * // 6
  30. * ```
  31. *
  32. * Both Observable `a` and `b` will emit their values directly and synchronously once they are subscribed to.
  33. *
  34. * If we instead use the `subscribeOn` operator declaring that we want to use the {@link asyncScheduler} for values emitted by Observable `a`:
  35. *
  36. * ```ts
  37. * import { of, subscribeOn, asyncScheduler, merge } from 'rxjs';
  38. *
  39. * const a = of(1, 2, 3).pipe(subscribeOn(asyncScheduler));
  40. * const b = of(4, 5, 6);
  41. *
  42. * merge(a, b).subscribe(console.log);
  43. *
  44. * // Outputs
  45. * // 4
  46. * // 5
  47. * // 6
  48. * // 1
  49. * // 2
  50. * // 3
  51. * ```
  52. *
  53. * The reason for this is that Observable `b` emits its values directly and synchronously like before
  54. * but the emissions from `a` are scheduled on the event loop because we are now using the {@link asyncScheduler} for that specific Observable.
  55. *
  56. * @param scheduler The {@link SchedulerLike} to perform subscription actions on.
  57. * @param delay A delay to pass to the scheduler to delay subscriptions
  58. * @return A function that returns an Observable modified so that its
  59. * subscriptions happen on the specified {@link SchedulerLike}.
  60. */
  61. export declare function subscribeOn<T>(scheduler: SchedulerLike, delay?: number): MonoTypeOperatorFunction<T>;
  62. //# sourceMappingURL=subscribeOn.d.ts.map