本文整理汇总了TypeScript中rxjs/Rx.Subject.observeOn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subject.observeOn方法的具体用法?TypeScript Subject.observeOn怎么用?TypeScript Subject.observeOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Subject
的用法示例。
在下文中一共展示了Subject.observeOn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
/**
* Creates a new Reactive Command.
* @param canRun An observable that determines whether the given task is allowed to run at a given moment.
* @param task A function that returns an observable that represents the asynchronous operation.
* @param scheduler The scheduler that all of the results should be observed on.
*/
constructor(private task: (args: TArgs) => Observable<TResult>, private canRun: Observable<boolean>, private scheduler: Scheduler) {
if (!task) {
throw new Error("The task parameter must be supplied");
}
if (!canRun) {
throw new Error("The canRun parameter must be supplied");
}
if (!scheduler) {
throw new Error("The scheduler parameter must be supplied");
}
this._executionInfo = new Subject<ExecutionInfo<TResult>>();
this._synchronizedExcecutionInfo = this._executionInfo;
this._exceptions = new Subject<any>();
// Implementation mostly taken from:
// https://github.com/reactiveui/ReactiveUI/blob/rxui7-master/ReactiveUI/ReactiveCommand.cs#L628
this._isExecuting = this._synchronizedExcecutionInfo
.observeOn(scheduler)
.map(info => info.demarcation === ExecutionDemarcation.Begin)
.startWith(false)
.distinctUntilChanged()
.publishReplay(1)
.refCount();
this._canExecute = this.canRun
.catch(ex => {
this._exceptions.next(ex);
return Observable.of(false);
})
.startWith(false)
.combineLatest(this._isExecuting, (canRun, isExecuting) => {
return canRun && !isExecuting;
})
.distinctUntilChanged()
.publishReplay(1)
.refCount();
this._results = this._synchronizedExcecutionInfo
.observeOn(scheduler)
.filter(info => info.demarcation === ExecutionDemarcation.EndWithResult)
.map(info => info.result);
// Make sure that can execute is triggered to be a hot observable.
this._canExecuteSubscription = this._canExecute.subscribe();
}