use of com.oath.cyclops.types.reactive.QueueBasedSubscriber in project cyclops by aol.
the class ReactiveSeq method merge.
default ReactiveSeq<T> merge(Adapter<T>... adapters) {
return defer(() -> {
Publisher<T>[] publishers = ReactiveSeq.of(adapters).map(a -> a.stream()).toArray(n -> new Publisher[n]);
final Counter c = new Counter();
c.active.set(publishers.length + 1);
final QueueBasedSubscriber<T> init = QueueBasedSubscriber.subscriber(QueueFactories.boundedQueue(5_000), c, publishers.length);
final Supplier<Continuation> sp = () -> {
backpressureAware().subscribe(init);
for (final Publisher next : publishers) {
next.subscribe(QueueBasedSubscriber.subscriber(init.getQueue(), c, publishers.length));
}
init.close();
return Continuation.empty();
};
final Continuation continuation = new Continuation(sp);
init.addContinuation(continuation);
return ReactiveSeq.fromStream(init.jdkStream());
});
}
Aggregations