Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.x: ConcatMapEager allow nulls from inner Observables. #3630

Merged
merged 1 commit into from
Jan 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/main/java/rx/internal/operators/OperatorEagerConcatMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void drain() {

final AtomicLong requested = sharedProducer;
final Subscriber<? super R> actualSubscriber = this.actual;
final NotificationLite<R> nl = NotificationLite.instance();

for (;;) {

Expand Down Expand Up @@ -200,13 +201,13 @@ void drain() {
long emittedAmount = 0L;
boolean unbounded = requestedAmount == Long.MAX_VALUE;

Queue<R> innerQueue = innerSubscriber.queue;
Queue<Object> innerQueue = innerSubscriber.queue;
boolean innerDone = false;


for (;;) {
outerDone = innerSubscriber.done;
R v = innerQueue.peek();
Object v = innerQueue.peek();
empty = v == null;

if (outerDone) {
Expand Down Expand Up @@ -237,7 +238,7 @@ void drain() {
innerQueue.poll();

try {
actualSubscriber.onNext(v);
actualSubscriber.onNext(nl.getValue(v));
} catch (Throwable ex) {
Exceptions.throwOrReport(ex, actualSubscriber, v);
return;
Expand Down Expand Up @@ -271,27 +272,29 @@ void drain() {

static final class EagerInnerSubscriber<T> extends Subscriber<T> {
final EagerOuterSubscriber<?, T> parent;
final Queue<T> queue;
final Queue<Object> queue;
final NotificationLite<T> nl;

volatile boolean done;
Throwable error;

public EagerInnerSubscriber(EagerOuterSubscriber<?, T> parent, int bufferSize) {
super();
this.parent = parent;
Queue<T> q;
Queue<Object> q;
if (UnsafeAccess.isUnsafeAvailable()) {
q = new SpscArrayQueue<T>(bufferSize);
q = new SpscArrayQueue<Object>(bufferSize);
} else {
q = new SpscAtomicArrayQueue<T>(bufferSize);
q = new SpscAtomicArrayQueue<Object>(bufferSize);
}
this.queue = q;
this.nl = NotificationLite.instance();
request(bufferSize);
}

@Override
public void onNext(T t) {
queue.offer(t);
queue.offer(nl.next(t));
parent.drain();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,20 @@ public void call(Integer t) {
ts.assertNotCompleted();
Assert.assertEquals(RxRingBuffer.SIZE, count.get());
}

@Test
public void testInnerNull() {
TestSubscriber<Object> ts = TestSubscriber.create();

Observable.just(1).concatMapEager(new Func1<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> call(Integer t) {
return Observable.just(null);
}
}).subscribe(ts);

ts.assertNoErrors();
ts.assertCompleted();
ts.assertValue(null);
}
}