import { Operator } from '../Operator'; import { IScheduler } from '../Scheduler'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; import { TeardownLogic } from '../Subscription'; import { SubscribeOnObservable } from '../observable/SubscribeOnObservable'; import { MonoTypeOperatorFunction } from '../interfaces'; /** * Asynchronously subscribes Observers to this Observable on the specified IScheduler. * * * * @param {Scheduler} scheduler - The IScheduler to perform subscription actions on. * @return {Observable} The source Observable modified so that its subscriptions happen on the specified IScheduler. . * @method subscribeOn * @owner Observable */ export function subscribeOn(scheduler: IScheduler, delay: number = 0): MonoTypeOperatorFunction { return function subscribeOnOperatorFunction(source: Observable): Observable { return source.lift(new SubscribeOnOperator(scheduler, delay)); }; } class SubscribeOnOperator implements Operator { constructor(private scheduler: IScheduler, private delay: number) { } call(subscriber: Subscriber, source: any): TeardownLogic { return new SubscribeOnObservable( source, this.delay, this.scheduler ).subscribe(subscriber); } }