目前我有一段代码
this.save()
.pipe(switchMap(() => this.unlock()))
.subscribe(...);save和unlock实现如下
private save(): Observable<void> {
return new Observable(subscriber => {
this.xmlService.save(..., () => {
...
subscriber.next();
subscriber.complete();
});
});
}
private unlock(): Observable<void> {
return this.httpService.unlock(this.id);
}由于unlock实际上不依赖于save返回的值,所以我可以使用switchMapTo吗?
this.save()
.pipe(switchMapTo(this.unlock()))
.subscribe(...);还是我误解了*To变体的行为?
发布于 2019-06-10 15:13:44
switchMapTo与switchMap完全相同,只不过它需要一个可观察的函数而不是回调函数。请参阅源代码:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/switchMapTo.ts#L56
https://stackoverflow.com/questions/56526804
复制相似问题