/** * Return a standard (unextended) JDK Stream connected to this Queue * To disconnect cleanly close the queue * * <pre> * {@code * use queue.stream().parallel() to convert to a parallel Stream * } * </pre> * @see Queue#jdkStream(int) for an alternative that sends more poision pills for use with parallel Streams. * * @return Java 8 Stream connnected to this Queue */ public Stream<T> jdkStream() { return jdkStream(2); }
@Override public Iterator<T> iterator() { return host.jdkStream().iterator(); }
default <R> R foldParallel(Function<? super Stream<T>,? extends R> fn){ Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue().build().withTimeout(1); AtomicReference<Continuation> ref = new AtomicReference<>(null); Continuation cont = new Continuation(()->{ if(ref.get()==null && ref.compareAndSet(null,Continuation.empty())){ try { //use the first consuming thread to tell this Stream onto the Queue this.spliterator().forEachRemaining(queue::offer); }finally { queue.close(); } } return Continuation.empty(); }); ; queue.addContinuation(cont); return fn.apply(queue.jdkStream().parallel()); } default <R> R foldParallel(ForkJoinPool fj,Function<? super Stream<T>,? extends R> fn){
/** * Return a standard (unextended) JDK Stream connected to this Queue * To disconnect cleanly close the queue * * <pre> * {@code * use queue.stream().parallel() to convert to a parallel Stream * } * </pre> * @see Queue#jdkStream(int) for an alternative that sends more poision pills for use with parallel Streams. * * @return Java 8 Stream connnected to this Queue */ public Stream<T> jdkStream() { return jdkStream(2); }
@Override public Iterator<T> iterator() { return host.jdkStream().iterator(); }
/** * Create a pushable JDK 8 Stream * * <pre> * {@code * PushableStream<Integer> pushable = StreamSource.ofUnbounded() .stream(); pushable.getInput() .add(10); pushable.getInput() .close(); pushable.getStream().collect(CyclopsCollectors.toList()) //[10] * * } * </pre> * * @return PushableStream that can accept data to push into a Java 8 Stream * to push it to the Stream */ public <T> PushableStream<T> stream() { final Queue<T> q = createQueue(); return new PushableStream<T>( q, q.jdkStream()); }
@Override default ReactiveSeq<U> stream() { return Streams.oneShotStream(toQueue().jdkStream(getSubscription())); }
default <R> R foldParallel(Function<? super Stream<T>,? extends R> fn){ Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue().build().withTimeout(1); AtomicReference<Continuation> ref = new AtomicReference<>(null); Continuation cont = new Continuation(()->{ if(ref.get()==null && ref.compareAndSet(null,Continuation.empty())){ try { //use the first consuming thread to tell this Stream onto the Queue this.spliterator().forEachRemaining(queue::offer); }finally { queue.close(); } } return Continuation.empty(); }); ; queue.addContinuation(cont); return fn.apply(queue.jdkStream().parallel()); } default <R> R foldParallel(ForkJoinPool fj,Function<? super Stream<T>,? extends R> fn){
Stream<InternalEvent> input = this.eventQueue.jdkStream();
Stream<InternalEvent> input = this.eventQueue.jdkStream();