File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
main/java/rx/internal/operators
test/java/rx/internal/operators Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,10 @@ public OnSubscribeFromIterable(Iterable<? extends T> iterable) {
4444 @ Override
4545 public void call (final Subscriber <? super T > o ) {
4646 final Iterator <? extends T > it = is .iterator ();
47- o .setProducer (new IterableProducer <T >(o , it ));
47+ if (!it .hasNext () && !o .isUnsubscribed ())
48+ o .onCompleted ();
49+ else
50+ o .setProducer (new IterableProducer <T >(o , it ));
4851 }
4952
5053 private static final class IterableProducer <T > implements Producer {
Original file line number Diff line number Diff line change 2727import java .util .Iterator ;
2828import java .util .concurrent .CountDownLatch ;
2929import java .util .concurrent .TimeUnit ;
30+ import java .util .concurrent .atomic .AtomicBoolean ;
3031
3132import org .junit .Test ;
3233import org .mockito .Mockito ;
@@ -74,12 +75,12 @@ public Iterator<String> iterator() {
7475
7576 @ Override
7677 public boolean hasNext () {
77- return i ++ < 3 ;
78+ return i < 3 ;
7879 }
7980
8081 @ Override
8182 public String next () {
82- return String .valueOf (i );
83+ return String .valueOf (++ i );
8384 }
8485
8586 @ Override
@@ -193,5 +194,31 @@ public void onNext(Integer t) {
193194 assertTrue (latch .await (10 , TimeUnit .SECONDS ));
194195 }
195196
197+ @ Test
198+ public void testFromEmptyIterableWhenZeroRequestedShouldStillEmitOnCompletedEagerly () {
199+ final AtomicBoolean completed = new AtomicBoolean (false );
200+ Observable .from (Collections .emptyList ()).subscribe (new Subscriber <Object >() {
201+
202+ @ Override
203+ public void onStart () {
204+ request (0 );
205+ }
206+
207+ @ Override
208+ public void onCompleted () {
209+ completed .set (true );
210+ }
196211
212+ @ Override
213+ public void onError (Throwable e ) {
214+
215+ }
216+
217+ @ Override
218+ public void onNext (Object t ) {
219+
220+ }});
221+ assertTrue (completed .get ());
222+ }
223+
197224}
You can’t perform that action at this time.
0 commit comments