1 import { Operator } from '../Operator';
2 import { Subscriber } from '../Subscriber';
3 import { Notification } from '../Notification';
4 import { MonoTypeOperatorFunction, PartialObserver, SchedulerAction, SchedulerLike, TeardownLogic } from '../types';
7 * Re-emits all notifications from source Observable with specified scheduler.
9 * <span class="informal">Ensure a specific scheduler is used, from outside of an Observable.</span>
11 * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule
12 * notifications emitted by the source Observable. It might be useful, if you do not have control over
13 * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.
15 * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,
16 * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal
17 * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits
18 * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.
19 * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split
20 * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source
21 * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a
22 * little bit more, to ensure that they are emitted at expected moments.
24 * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications
25 * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`
26 * will delay all notifications - including error notifications - while `delay` will pass through error
27 * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator
28 * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used
29 * for notification emissions in general.
32 * Ensure values in subscribe are called just before browser repaint.
34 * import { interval } from 'rxjs';
35 * import { observeOn } from 'rxjs/operators';
37 * const intervals = interval(10); // Intervals are scheduled
38 * // with async scheduler by default...
40 * observeOn(animationFrameScheduler), // ...but we will observe on animationFrame
41 * ) // scheduler to ensure smooth animation.
43 * someDiv.style.height = val + 'px';
49 * @param {SchedulerLike} scheduler Scheduler that will be used to reschedule notifications from source Observable.
50 * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.
51 * @return {Observable<T>} Observable that emits the same notifications as the source Observable,
52 * but with provided scheduler.
57 export declare function observeOn<T>(scheduler: SchedulerLike, delay?: number): MonoTypeOperatorFunction<T>;
58 export declare class ObserveOnOperator<T> implements Operator<T, T> {
61 constructor(scheduler: SchedulerLike, delay?: number);
62 call(subscriber: Subscriber<T>, source: any): TeardownLogic;
65 * We need this JSDoc comment for affecting ESDoc.
69 export declare class ObserveOnSubscriber<T> extends Subscriber<T> {
73 static dispatch(this: SchedulerAction<ObserveOnMessage>, arg: ObserveOnMessage): void;
74 constructor(destination: Subscriber<T>, scheduler: SchedulerLike, delay?: number);
75 private scheduleMessage;
76 protected _next(value: T): void;
77 protected _error(err: any): void;
78 protected _complete(): void;
80 export declare class ObserveOnMessage {
81 notification: Notification<any>;
82 destination: PartialObserver<any>;
83 constructor(notification: Notification<any>, destination: PartialObserver<any>);