@Test public void singletonIterableUnboundedRequest() { TestSubscriber<Integer> ts = new TestSubscriber<>(); Multi.create(Collections.singleton(1)) .subscribe(ts); assertThat(ts.getItems().isEmpty(), is(true)); assertThat(ts.isComplete(), is(false)); assertThat(ts.getLastError(), is(nullValue())); assertThat(ts.getSubcription(), is(notNullValue())); ts.requestMax(); assertEquals(ts.getItems(), Collections.singleton(1)); assertThat(ts.isComplete(), is(true)); assertThat(ts.getLastError(), is(nullValue())); }
@Override public void subscribe(Flow.Subscriber<? super T> subscriber) { Objects.requireNonNull(subscriber, "subscriber is null"); Iterator<T> iterator; boolean hasFirst; try { iterator = iterable.iterator(); hasFirst = iterator.hasNext(); } catch (Throwable ex) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onError(ex); return; } if (!hasFirst) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onComplete(); return; } subscriber.onSubscribe(new IteratorSubscription<>(subscriber, iterator)); }
MultiFromIterable implements Multi<T> { @Override public void subscribe(Flow.Subscriber<? super T> subscriber) { Objects.requireNonNull(subscriber, "subscriber is null"); Iterator<T> iterator; boolean hasFirst; try { iterator = iterable.iterator(); hasFirst = iterator.hasNext(); } catch (Throwable ex) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onError(ex); return; } if (!hasFirst) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onComplete(); return; } subscriber.onSubscribe(new IteratorSubscription<>(subscriber, iterator)); } }
MultiFromIterable implements Multi<T> { @Override public void subscribe(Flow.Subscriber<? super T> subscriber) { Objects.requireNonNull(subscriber, "subscriber is null"); Iterator<T> iterator; boolean hasFirst; try { iterator = iterable.iterator(); hasFirst = iterator.hasNext(); } catch (Throwable ex) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onError(ex); return; } if (!hasFirst) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onComplete(); return; } subscriber.onSubscribe(new IteratorSubscription<>(subscriber, iterator)); } MultiFromIterable(Iterable<T> iterable); }
MultiFromIterable implements Multi<T> { @Override public void subscribe(Flow.Subscriber<? super T> subscriber) { Objects.requireNonNull(subscriber, "subscriber is null"); Iterator<T> iterator; boolean hasFirst; try { iterator = iterable.iterator(); hasFirst = iterator.hasNext(); } catch (Throwable ex) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onError(ex); return; } if (!hasFirst) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onComplete(); return; } subscriber.onSubscribe(new IteratorSubscription<>(subscriber, iterator)); } MultiFromIterable(Iterable<T> iterable); @Override void subscribe(Flow.Subscriber<? super T> subscriber); }
MultiFromIterable implements Multi<T> { @Override public void subscribe(Flow.Subscriber<? super T> subscriber) { Objects.requireNonNull(subscriber, "subscriber is null"); Iterator<T> iterator; boolean hasFirst; try { iterator = iterable.iterator(); hasFirst = iterator.hasNext(); } catch (Throwable ex) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onError(ex); return; } if (!hasFirst) { subscriber.onSubscribe(EmptySubscription.INSTANCE); subscriber.onComplete(); return; } subscriber.onSubscribe(new IteratorSubscription<>(subscriber, iterator)); } MultiFromIterable(Iterable<T> iterable); @Override void subscribe(Flow.Subscriber<? super T> subscriber);  }