对反应堆执行以下操作的正确方法是什么:
类似(示例)的
public <T> CountDownLatch test(Flux<T> publisher, List<Subscriber<T>> subscribers) {
final CountDownLatch latch = new CountDownLatch(1);
publisher
.doOnSubscribe(subscription -> subscribers.forEach(s -> s.onSubscribe(subscription)))
.parallel(16)
.runOn(Schedulers.elastic())
.doOnNext(e -> subscribers.forEach(s -> s.onNext(e)))
.doOnError(e -> subscribers.forEach(s -> s.onError(e)))
.sequential()
.doOnComplete(() -> subscribers.forEach(Subscriber::onComplete))
.doFinally(sig -> latch.countDown())
.subscribe();
return latch;
}
这是正确的方法吗?可以做得更好吗?对于我来说,这段代码看起来并不漂亮,有多个“ forEach”循环等。