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) {
44
44
@ Override
45
45
public void call (final Subscriber <? super T > o ) {
46
46
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 ));
48
51
}
49
52
50
53
private static final class IterableProducer <T > implements Producer {
Original file line number Diff line number Diff line change 27
27
import java .util .Iterator ;
28
28
import java .util .concurrent .CountDownLatch ;
29
29
import java .util .concurrent .TimeUnit ;
30
+ import java .util .concurrent .atomic .AtomicBoolean ;
30
31
31
32
import org .junit .Test ;
32
33
import org .mockito .Mockito ;
@@ -74,12 +75,12 @@ public Iterator<String> iterator() {
74
75
75
76
@ Override
76
77
public boolean hasNext () {
77
- return i ++ < 3 ;
78
+ return i < 3 ;
78
79
}
79
80
80
81
@ Override
81
82
public String next () {
82
- return String .valueOf (i );
83
+ return String .valueOf (++ i );
83
84
}
84
85
85
86
@ Override
@@ -193,5 +194,31 @@ public void onNext(Integer t) {
193
194
assertTrue (latch .await (10 , TimeUnit .SECONDS ));
194
195
}
195
196
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
+ }
196
211
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
+
197
224
}
You can’t perform that action at this time.
0 commit comments