如何在RxJs中拆分流并重新组合子流最终结果

如何在RxJs中拆分流并重新组合子流最终结果,rxjs,Rxjs,我有一个可以发出两种消息的源流。我想将它们分成两个单独的流,一旦原始流完成,重新组合它们的最终发射值(如果不存在,则未定义) e、 g 问题是没有任何东西可以保证split1$和split2$都会发出值。如果发生这种情况,forkJoin将永远不会发射。 我可以用什么替换forkJoin以在源流完成时发出值。关于拆分流: 关于“完成时发出”,您不能改用completecallback吗.subscribe(()=>console.log('emissed')、null(()=>console.

我有一个可以发出两种消息的源流。我想将它们分成两个单独的流,一旦原始流完成,重新组合它们的最终发射值(如果不存在,则未定义)

e、 g

问题是没有任何东西可以保证split1$和split2$都会发出值。如果发生这种情况,forkJoin将永远不会发射。
我可以用什么替换forkJoin以在源流完成时发出值。

关于拆分流:

关于“完成时发出”,您不能改用
complete
callback吗
.subscribe(()=>console.log('emissed')、null(()=>console.log('Completed'))

否则,您可以使用
startWith
操作符来确保发出了某些内容

const [evens, odds] = source.pipe(partition(val => val % 2 === 0));
evens = evens.pipe(startWith(undefined)); // This will emit undefined before everything, so forkJoin will surely emit
forkJoin
构造函数中添加
startWith

forkJoin(evens.pipe(startWith(undefined)), odds.pipe(startWith(undefined)))
  .subscribe(console.log))

我不能使用完整的回调,因为我想在所有流都完成后使用结果数据。这是一个有效的选项,但会给我的代码带来噪音,因为如果我在拆分的流管道中进行任何登录,我必须对其进行过滤。只需在
StartWith
之前登录,或在
forkJoin
constructor中添加
StartWith
所以您不需要更改初始分区流。编辑了答案。
forkJoin(evens.pipe(startWith(undefined)), odds.pipe(startWith(undefined)))
  .subscribe(console.log))