@Override public Stream<T> unwrapStream() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> { queue.close(); }, () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream(); } return StreamSupport.stream(new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).spliterator(), false); }
@Override public Iterator<T> iterator() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Subscription[] sub = {null}; Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> queue.close(), () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream().iterator(); } return new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).iterator(); }
@Override public Publisher<Long> createPublisher(long elements) { return ReactiveSeq.fromIterable(new OperatorToIterable<Long, Long>(((ReactiveStreamX<Long>) Spouts.iterate(0l, i -> i + 1l).filter(i -> i % 2 == 0).limit(elements)).getSource(), e -> { throw ExceptionSoftener.throwSoftenedException(e); })); }
@Override public Stream<T> unwrapStream() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> { queue.close(); }, () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream(); } return StreamSupport.stream(new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).spliterator(), false); }
@Override public Iterator<T> iterator() { if (async == Type.NO_BACKPRESSURE) { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); AtomicBoolean wip = new AtomicBoolean(false); Subscription[] sub = {null}; Continuation cont = new Continuation(() -> { if (wip.compareAndSet(false, true)) { this.source.subscribeAll(queue::offer, i -> queue.close(), () -> queue.close()); } return Continuation.empty(); }); queue.addContinuation(cont); return queue.stream().iterator(); } return new OperatorToIterable<>(source, this.defaultErrorHandler, async == BACKPRESSURE).iterator(); }