Search in sources :

Example 1 with QueueBasedSubscriber

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());
    });
}
Also used : PersistentCollection(com.oath.cyclops.types.persistent.PersistentCollection) Continuation(com.oath.cyclops.types.futurestream.Continuation) DataWitness.reactiveSeq(com.oath.cyclops.hkt.DataWitness.reactiveSeq) HashMap(cyclops.data.HashMap) Seq(cyclops.data.Seq) Counter(com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RecoverableTraversable(com.oath.cyclops.types.traversable.RecoverableTraversable) ReversingLongArraySpliterator(com.oath.cyclops.internal.stream.spliterators.longs.ReversingLongArraySpliterator) Unit(com.oath.cyclops.types.factory.Unit) PrintWriter(java.io.PrintWriter) Contains(com.oath.cyclops.types.foldable.Contains) Monoid(cyclops.function.Monoid) com.oath.cyclops.async.adapters(com.oath.cyclops.async.adapters) ReversingDoubleArraySpliterator(com.oath.cyclops.internal.stream.spliterators.doubles.ReversingDoubleArraySpliterator) com.oath.cyclops.types.stream(com.oath.cyclops.types.stream) ReversingRangeLongSpliterator(com.oath.cyclops.internal.stream.spliterators.longs.ReversingRangeLongSpliterator) Queue(com.oath.cyclops.async.adapters.Queue) ReversingRangeIntSpliterator(com.oath.cyclops.internal.stream.spliterators.ints.ReversingRangeIntSpliterator) Function3(cyclops.function.Function3) Function4(cyclops.function.Function4) com.oath.cyclops.internal.stream.spliterators(com.oath.cyclops.internal.stream.spliterators) IterableX(com.oath.cyclops.types.traversable.IterableX) ExceptionSoftener(com.oath.cyclops.util.ExceptionSoftener) java.util.function(java.util.function) QueueBasedSubscriber(com.oath.cyclops.types.reactive.QueueBasedSubscriber) Tuple4(cyclops.data.tuple.Tuple4) Higher(com.oath.cyclops.hkt.Higher) To(com.oath.cyclops.types.foldable.To) Tuple3(cyclops.data.tuple.Tuple3) Tuple2(cyclops.data.tuple.Tuple2) java.util(java.util) ReversingIntArraySpliterator(com.oath.cyclops.internal.stream.spliterators.ints.ReversingIntArraySpliterator) java.util.stream(java.util.stream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Vector(cyclops.data.Vector) AtomicReference(java.util.concurrent.atomic.AtomicReference) Tuple(cyclops.data.tuple.Tuple) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) com.oath.cyclops.async(com.oath.cyclops.async) Subscriber(org.reactivestreams.Subscriber) ReactiveTransformable(com.oath.cyclops.types.functor.ReactiveTransformable) OnEmptySwitch(com.oath.cyclops.types.recoverable.OnEmptySwitch) PrintStream(java.io.PrintStream) cyclops.control(cyclops.control) Streams(cyclops.companion.Streams) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) lombok.val(lombok.val) TimeUnit(java.util.concurrent.TimeUnit) Reducer(cyclops.function.Reducer) AtomicLong(java.util.concurrent.atomic.AtomicLong) ForkJoinPool(java.util.concurrent.ForkJoinPool) OneShotStreamX(com.oath.cyclops.internal.stream.OneShotStreamX) Curry(cyclops.function.Curry) Enumeration(cyclops.data.Enumeration) Continuation(com.oath.cyclops.types.futurestream.Continuation) Counter(com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter) Publisher(org.reactivestreams.Publisher)

Aggregations

com.oath.cyclops.async (com.oath.cyclops.async)1 com.oath.cyclops.async.adapters (com.oath.cyclops.async.adapters)1 Queue (com.oath.cyclops.async.adapters.Queue)1 DataWitness.reactiveSeq (com.oath.cyclops.hkt.DataWitness.reactiveSeq)1 Higher (com.oath.cyclops.hkt.Higher)1 OneShotStreamX (com.oath.cyclops.internal.stream.OneShotStreamX)1 com.oath.cyclops.internal.stream.spliterators (com.oath.cyclops.internal.stream.spliterators)1 ReversingDoubleArraySpliterator (com.oath.cyclops.internal.stream.spliterators.doubles.ReversingDoubleArraySpliterator)1 ReversingIntArraySpliterator (com.oath.cyclops.internal.stream.spliterators.ints.ReversingIntArraySpliterator)1 ReversingRangeIntSpliterator (com.oath.cyclops.internal.stream.spliterators.ints.ReversingRangeIntSpliterator)1 ReversingLongArraySpliterator (com.oath.cyclops.internal.stream.spliterators.longs.ReversingLongArraySpliterator)1 ReversingRangeLongSpliterator (com.oath.cyclops.internal.stream.spliterators.longs.ReversingRangeLongSpliterator)1 Unit (com.oath.cyclops.types.factory.Unit)1 Contains (com.oath.cyclops.types.foldable.Contains)1 To (com.oath.cyclops.types.foldable.To)1 ReactiveTransformable (com.oath.cyclops.types.functor.ReactiveTransformable)1 Continuation (com.oath.cyclops.types.futurestream.Continuation)1 PersistentCollection (com.oath.cyclops.types.persistent.PersistentCollection)1 QueueBasedSubscriber (com.oath.cyclops.types.reactive.QueueBasedSubscriber)1 Counter (com.oath.cyclops.types.reactive.QueueBasedSubscriber.Counter)1