Skip to content

Delay: error cut ahead was not properly serialized #3028

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

Merged
merged 1 commit into from
Jun 22, 2015
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
26 changes: 21 additions & 5 deletions src/main/java/rx/internal/operators/OperatorDelay.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,36 @@ public Subscriber<? super T> call(final Subscriber<? super T> child) {
final Worker worker = scheduler.createWorker();
child.add(worker);
return new Subscriber<T>(child) {

// indicates an error cut ahead
// accessed from the worker thread only
boolean done;
@Override
public void onCompleted() {
worker.schedule(new Action0() {

@Override
public void call() {
child.onCompleted();
if (!done) {
done = true;
child.onCompleted();
}
}

}, delay, unit);
}

@Override
public void onError(Throwable e) {
child.onError(e);
public void onError(final Throwable e) {
worker.schedule(new Action0() {
@Override
public void call() {
if (!done) {
done = true;
child.onError(e);
worker.unsubscribe();
}
}
});
}

@Override
Expand All @@ -73,7 +87,9 @@ public void onNext(final T t) {

@Override
public void call() {
child.onNext(t);
if (!done) {
child.onNext(t);
}
}

}, delay, unit);
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/rx/internal/operators/OperatorDelayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,27 @@ public Integer call(Integer t) {
ts.assertNoErrors();
assertEquals(RxRingBuffer.SIZE * 2, ts.getOnNextEvents().size());
}

@Test
public void testErrorRunsBeforeOnNext() {
TestScheduler test = Schedulers.test();

PublishSubject<Integer> ps = PublishSubject.create();

TestSubscriber<Integer> ts = TestSubscriber.create();

ps.delay(1, TimeUnit.SECONDS, test).subscribe(ts);

ps.onNext(1);

test.advanceTimeBy(500, TimeUnit.MILLISECONDS);

ps.onError(new TestException());

test.advanceTimeBy(1, TimeUnit.SECONDS);

ts.assertNoValues();
ts.assertError(TestException.class);
ts.assertNotCompleted();
}
}