Rxjs 如何获得承诺
两者之间有区别吗Rxjs 如何获得承诺,rxjs,rxjs5,Rxjs,Rxjs5,两者之间有区别吗 var source1 = Rx.Observable.of(42); const oneSubscription = source1.subscribe({ next: x => console.log(x) }); oneSubscription.unsubscribe(); 及 我认为要创造一个承诺,你必须先订阅它 但是在source2的情况下,它只是在没有订阅的情况下工作 可能有人可以解释。那是因为forEach内部也有订阅 /** * Subscr
var source1 = Rx.Observable.of(42);
const oneSubscription = source1.subscribe({
next: x => console.log(x)
});
oneSubscription.unsubscribe();
及
我认为要创造一个承诺,你必须先订阅它
但是在source2
的情况下,它只是在没有订阅的情况下工作
可能有人可以解释。那是因为
forEach
内部也有订阅
/**
* Subscribes an o to the observable sequence.
* @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
* @returns {Diposable} A disposable handling the subscriptions and unsubscriptions.
*/
forEach(observer: IObserver<T>): IDisposable;
/**
*给可观测序列标上一个o。
*@param{Mixed}[oOrOnNext]为可观察序列中的每个元素接收通知或调用操作的对象。
*@param{Function}[onError]在可观察序列异常终止时调用的操作。
*@param{Function}[onCompleted]在可观察序列优雅终止时调用的操作。
*@returns{Diposable}一个处理订阅和取消订阅的一次性文件。
*/
forEach(观察者:IObserver):IDisposable;
这是因为forEach
也在内部订阅
/**
* Subscribes an o to the observable sequence.
* @param {Mixed} [oOrOnNext] The object that is to receive notifications or an action to invoke for each element in the observable sequence.
* @param {Function} [onError] Action to invoke upon exceptional termination of the observable sequence.
* @param {Function} [onCompleted] Action to invoke upon graceful termination of the observable sequence.
* @returns {Diposable} A disposable handling the subscriptions and unsubscriptions.
*/
forEach(observer: IObserver<T>): IDisposable;
/**
*给可观测序列标上一个o。
*@param{Mixed}[oOrOnNext]为可观察序列中的每个元素接收通知或调用操作的对象。
*@param{Function}[onError]在可观察序列异常终止时调用的操作。
*@param{Function}[onCompleted]在可观察序列优雅终止时调用的操作。
*@returns{Diposable}一个处理订阅和取消订阅的一次性文件。
*/
forEach(观察者:IObserver):IDisposable;
如何访问next
,error
,在forEach
中完成
?您可以添加更多功能,如订阅
,请参阅@sreginogemoh此答案对您有帮助吗?您如何访问next
,error
,在forEach
中完成
?您可以添加更多功能,如在订阅
,请参阅@sreginogemoh此答案对您有帮助吗?