@Override public void request(long n) { if(n<=0) { onError.accept(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); return; } if(!isOpen) return; super.request(n); upstream[0].request(n ); }
@Override public void request(long n) { if(n<=0) { onError.accept(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); return; } if(!isOpen) return; super.request(n); upstream[0].request(n ); }
@Override public void request(long n) { if(n<=0) { onError.accept(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); return; } if(!isOpen) return; super.request(n); upstream[0].request(n); }
@Override public void subscribeAll(Consumer<? super T> onNext, Consumer<? super Throwable> onError, Runnable onComplete) { this.action=onNext; this.error = onError; this.onComplete = onComplete; this.initialized.set(true); onInit.run(); subscription.request(Long.MAX_VALUE); }
@Override public void request(long n) { if (n <= 0) { onError.accept(new IllegalArgumentException("3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); return; } super.request(n); ref[0].request(n); }
@Override public <X extends Throwable> Subscription forEach(final long numberOfElements, final Consumer<? super T> consumer) { StreamSubscription sub = source.subscribe(consumer, this.defaultErrorHandler, () -> { }); if(numberOfElements>0) sub.request(numberOfElements); return sub; }
@Override public <X extends Throwable> Subscription forEach(final long numberOfElements, final Consumer<? super T> consumer, final Consumer<? super Throwable> consumerError) { StreamSubscription sub = source.subscribe(consumer, consumerError, () -> { }); if(numberOfElements>0) sub.request(numberOfElements); return sub; }
@Override public <X extends Throwable> Subscription forEach(final long numberOfElements, final Consumer<? super T> consumer, final Consumer<? super Throwable> consumerError, final Runnable onComplete) { StreamSubscription sub = source.subscribe(consumer, consumerError, onComplete); if(numberOfElements>0) sub.request(numberOfElements); return sub; }
@Override public void request(long n) { s.request(n); super.request(n); }
@Override public void forEachAsync(final Consumer<? super T> action) { if (async == Type.NO_BACKPRESSURE) source.subscribeAll(action, this.defaultErrorHandler, () -> { }); else source.subscribe(action, this.defaultErrorHandler, () -> { }).request(Long.MAX_VALUE); }
@Override public <X extends Throwable> void forEach(final Consumer<? super T> consumerElement, final Consumer<? super Throwable> consumerError, final Runnable onComplete) { if (async != Type.NO_BACKPRESSURE) { this.source.subscribe(consumerElement, consumerError, onComplete).request(Long.MAX_VALUE); } else { source.subscribeAll(consumerElement, consumerError, onComplete); } }
@Override public <X extends Throwable> void forEach(final Consumer<? super T> consumerElement, final Consumer<? super Throwable> consumerError) { if (async != Type.NO_BACKPRESSURE) { this.source.subscribe(consumerElement, consumerError, () -> { }).request(Long.MAX_VALUE); } else { source.subscribeAll(consumerElement, consumerError, () -> { }); } }
@Override public void forEachOrdered(final Consumer<? super T> consumer) { Future<Boolean> complete = Future.future(); if (async == Type.NO_BACKPRESSURE) { source.subscribeAll(consumer, this.defaultErrorHandler, () -> complete.complete(true)); } else { source.subscribe(consumer, this.defaultErrorHandler, () -> complete.complete(true)).request(Long.MAX_VALUE); } complete.get(); }
@Test public void request1(){ new SpliteratorToOperator<Integer>(ReactiveSeq.of(1,2,3).spliterator()) .subscribe(values::add,errors::add,()->onComplete=true) .request(1l); assertThat(values.size(),equalTo(1)); }
@Test public void requestTwo(){ new SpliteratorToOperator<Integer>(ReactiveSeq.fill(10).limit(100).spliterator()) .subscribe(values::add,errors::add,()->onComplete=true) .request(2l); assertThat(values.size(),equalTo(2)); }