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AI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAQO,6CAAe,GAAvB,UAAwB,YAA+B;QACrD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAC9B,mBAAmB,CAAC,QAAQ,EAC5B,IAAI,CAAC,KAAK,EACV,IAAI,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CACrD,CAAC,CAAC;IACL,CAAC;IAES,mCAAK,GAAf,UAAgB,KAAQ;QACtB,IAAI,CAAC,eAAe,CAAC,2BAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACvD,CAAC;IAES,oCAAM,GAAhB,UAAiB,GAAQ;QACvB,IAAI,CAAC,eAAe,CAAC,2BAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAES,uCAAS,GAAnB;QACE,IAAI,CAAC,eAAe,CAAC,2BAAY,CAAC,cAAc,EAAE,CAAC,CAAC;IACtD,CAAC;IACH,0BAAC;AAAD,CAAC,AAhCD,CAA4C,uBAAU,GAgCrD;AAhCY,2BAAmB,sBAgC/B,CAAA;AAED;IACE,0BAAmB,YAA+B,EAC/B,WAAiC;QADjC,iBAAY,GAAZ,YAAY,CAAmB;QAC/B,gBAAW,GAAX,WAAW,CAAsB;IACpD,CAAC;IACH,uBAAC;AAAD,CAAC,AAJD,IAIC;AAJY,wBAAgB,mBAI5B,CAAA","sourcesContent":["import { Observable } from '../Observable';\nimport { IScheduler } from '../Scheduler';\nimport { Operator } from '../Operator';\nimport { PartialObserver } from '../Observer';\nimport { Subscriber } from '../Subscriber';\nimport { Notification } from '../Notification';\nimport { TeardownLogic } from '../Subscription';\nimport { Action } from '../scheduler/Action';\nimport { MonoTypeOperatorFunction } from '../interfaces';\n\n/**\n *\n * Re-emits all notifications from source Observable with specified scheduler.\n *\n * <span class=\"informal\">Ensure a specific scheduler is used, from outside of an Observable.</span>\n *\n * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule\n * notifications emitted by the source Observable. It might be useful, if you do not have control over\n * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.\n *\n * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,\n * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal\n * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits\n * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.\n * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split\n * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source\n * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a\n * little bit more, to ensure that they are emitted at expected moments.\n *\n * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications\n * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`\n * will delay all notifications - including error notifications - while `delay` will pass through error\n * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator\n * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used\n * for notification emissions in general.\n *\n * @example <caption>Ensure values in subscribe are called just before browser repaint.</caption>\n * const intervals = Rx.Observable.interval(10); // Intervals are scheduled\n * // with async scheduler by default...\n *\n * intervals\n * .observeOn(Rx.Scheduler.animationFrame) // ...but we will observe on animationFrame\n * .subscribe(val => { // scheduler to ensure smooth animation.\n * someDiv.style.height = val + 'px';\n * });\n *\n * @see {@link delay}\n *\n * @param {IScheduler} scheduler Scheduler that will be used to reschedule notifications from source Observable.\n * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.\n * @return {Observable<T>} Observable that emits the same notifications as the source Observable,\n * but with provided scheduler.\n *\n * @method observeOn\n * @owner Observable\n */\nexport function observeOn<T>(scheduler: IScheduler, delay: number = 0): MonoTypeOperatorFunction<T> {\n return function observeOnOperatorFunction(source: Observable<T>): Observable<T> {\n return source.lift(new ObserveOnOperator(scheduler, delay));\n };\n}\n\nexport class ObserveOnOperator<T> implements Operator<T, T> {\n constructor(private scheduler: IScheduler, private delay: number = 0) {\n }\n\n call(subscriber: Subscriber<T>, source: any): TeardownLogic {\n return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class ObserveOnSubscriber<T> extends Subscriber<T> {\n static dispatch(this: Action<ObserveOnMessage>, arg: ObserveOnMessage) {\n const { notification, destination } = arg;\n notification.observe(destination);\n this.unsubscribe();\n }\n\n constructor(destination: Subscriber<T>,\n private scheduler: IScheduler,\n private delay: number = 0) {\n super(destination);\n }\n\n private scheduleMessage(notification: Notification<any>): void {\n this.add(this.scheduler.schedule(\n ObserveOnSubscriber.dispatch,\n this.delay,\n new ObserveOnMessage(notification, this.destination)\n ));\n }\n\n protected _next(value: T): void {\n this.scheduleMessage(Notification.createNext(value));\n }\n\n protected _error(err: any): void {\n this.scheduleMessage(Notification.createError(err));\n }\n\n protected _complete(): void {\n this.scheduleMessage(Notification.createComplete());\n }\n}\n\nexport class ObserveOnMessage {\n constructor(public notification: Notification<any>,\n public destination: PartialObserver<any>) {\n }\n}\n"]}