【发布时间】:2020-09-11 08:59:30
【问题描述】:
我正在寻找一种方法来简化这一点并避免在我的管道中管理订阅。
关于我的代码的总体思路:
this.start$ubject // waiting for users call to start
.pipe(
mergeMap(() => from(this.thirdPartyService.start())), // now i need to wait for smth to start
tap(() => {
// only after thirdPartyService started i can subscribe because prior to that they are undefined
this.subscriptions.push(
this.thirdPartyService.alfa$.subscribe(this.first$ubject),
this.thirdPartyService.beta$.subscribe(this.second$ubject),
);
}),
);
有什么办法可以解决吗? takeWhile 之类的东西,但要订阅?
【问题讨论】:
-
我有一些问题: start$ubject 会发出多少次值?当它在
this.thirdPartyService.start()、alfa$和beta$完成之前多次发射时,它将多次运行thirdPartyService。所以首先,这是你想要的。有一种方法可以管理您的订阅。您可以使用 zip 运算符代替选项卡。 -
有必要将您的订阅推送到 this.subscriptions 中吗?很抱歉所有这些问题。正确解决问题也很重要。
-
@SerkanSipahi start$ubject 将发出多次,每次我需要启动该服务并收到唯一的
alfa$和beta$
标签: asynchronous rxjs rxjs5 rxjs6