Skip to content

Commit d217209

Browse files
Take Unsubscribes Before OnNext
To prevent issues such as #1791
1 parent bf1a4f3 commit d217209

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/rx/internal/operators/OperatorTake.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ public void onError(Throwable e) {
6161
@Override
6262
public void onNext(T i) {
6363
if (!isUnsubscribed()) {
64-
child.onNext(i);
6564
if (++count >= limit) {
6665
completed = true;
67-
child.onCompleted();
66+
// unsubscribe before emitting onNext so shutdown happens before possible effects
67+
// of onNext such as product.request(n) calls be sent upstream.
6868
unsubscribe();
6969
}
70+
child.onNext(i);
71+
if (completed) {
72+
child.onCompleted();
73+
}
7074
}
7175
}
7276

0 commit comments

Comments
 (0)