Skip to content

Commit d52cce9

Browse files
davidmotenakarnokd
authored andcommitted
doAfterNext - prevent post-terminal emission (#4903)
1 parent a39fa89 commit d52cce9

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/main/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ static final class DoAfterSubscriber<T> extends BasicFuseableSubscriber<T, T> {
5555

5656
@Override
5757
public void onNext(T t) {
58+
if (done) {
59+
return;
60+
}
5861
actual.onNext(t);
5962

6063
if (sourceMode == NONE) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.reactivex.flowable;
17+
18+
import static org.junit.Assert.assertEquals;
19+
20+
import java.util.concurrent.atomic.AtomicInteger;
21+
22+
import org.junit.Test;
23+
24+
import io.reactivex.functions.Consumer;
25+
26+
public class FlowableDoAfterNextTest {
27+
28+
@Test
29+
public void testIfFunctionThrowsThatNoMoreEventsAreProcessed() {
30+
final AtomicInteger count = new AtomicInteger();
31+
final RuntimeException e = new RuntimeException();
32+
Burst.items(1, 2).create()
33+
.doAfterNext(new Consumer<Integer>() {
34+
@Override
35+
public void accept(Integer t) throws Exception {
36+
count.incrementAndGet();
37+
throw e;
38+
}})
39+
.test()
40+
.assertError(e)
41+
.assertValue(1);
42+
assertEquals(1, count.get());
43+
}
44+
}

0 commit comments

Comments
 (0)