UNPKG

1.92 kBTypeScriptView Raw
1import { 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 */
61export declare function subscribeOn<T>(scheduler: SchedulerLike, delay?: number): MonoTypeOperatorFunction<T>;
62//# sourceMappingURL=subscribeOn.d.ts.map
\No newline at end of file