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

3.x: Fix window (boundary, start/end) cancel and abandonment #6762

Merged
merged 1 commit into from
Dec 17, 2019
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
20 changes: 20 additions & 0 deletions src/main/java/io/reactivex/rxjava3/core/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -17965,6 +17965,11 @@ public final Flowable<Flowable<T>> window(
* Publisher.
* <p>
* <img width="640" height="475" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window8.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The outer Publisher of this operator does not support backpressure as it uses a {@code boundary} Publisher to control data
Expand Down Expand Up @@ -17995,6 +18000,11 @@ public final <B> Flowable<Flowable<T>> window(Publisher<B> boundaryIndicator) {
* Publisher.
* <p>
* <img width="640" height="475" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window8.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The outer Publisher of this operator does not support backpressure as it uses a {@code boundary} Publisher to control data
Expand Down Expand Up @@ -18031,6 +18041,11 @@ public final <B> Flowable<Flowable<T>> window(Publisher<B> boundaryIndicator, in
* {@code closingSelector} emits an item.
* <p>
* <img width="640" height="550" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window2.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The outer Publisher of this operator doesn't support backpressure because the emission of new
Expand Down Expand Up @@ -18068,6 +18083,11 @@ public final <U, V> Flowable<Flowable<T>> window(
* {@code closingSelector} emits an item.
* <p>
* <img width="640" height="550" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window2.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The outer Publisher of this operator doesn't support backpressure because the emission of new
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/io/reactivex/rxjava3/core/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -14536,6 +14536,11 @@ public final Observable<Observable<T>> window(long count, long skip, int bufferS
* current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="335" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window7.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.</dd>
Expand Down Expand Up @@ -14564,6 +14569,11 @@ public final Observable<Observable<T>> window(long timespan, long timeskip, Time
* current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="335" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window7.s.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
Expand Down Expand Up @@ -14594,6 +14604,11 @@ public final Observable<Observable<T>> window(long timespan, long timeskip, Time
* current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="335" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window7.s.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
Expand Down Expand Up @@ -14630,6 +14645,11 @@ public final Observable<Observable<T>> window(long timespan, long timeskip, Time
* ObservableSource emits the current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="375" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window5.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.</dd>
Expand Down Expand Up @@ -14658,6 +14678,11 @@ public final Observable<Observable<T>> window(long timespan, TimeUnit unit) {
* emits the current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="370" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window6.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.</dd>
Expand Down Expand Up @@ -14690,6 +14715,11 @@ public final Observable<Observable<T>> window(long timespan, TimeUnit unit,
* emits the current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="370" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window6.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} operates by default on the {@code computation} {@link Scheduler}.</dd>
Expand Down Expand Up @@ -14723,6 +14753,11 @@ public final Observable<Observable<T>> window(long timespan, TimeUnit unit,
* ObservableSource emits the current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="375" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window5.s.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
Expand Down Expand Up @@ -14754,6 +14789,11 @@ public final Observable<Observable<T>> window(long timespan, TimeUnit unit,
* current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="370" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window6.s.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
Expand Down Expand Up @@ -14788,6 +14828,11 @@ public final Observable<Observable<T>> window(long timespan, TimeUnit unit,
* current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="370" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window6.s.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
Expand Down Expand Up @@ -14824,6 +14869,11 @@ public final Observable<Observable<T>> window(long timespan, TimeUnit unit,
* current window and propagates the notification from the source ObservableSource.
* <p>
* <img width="640" height="370" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window6.s.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>You specify which {@link Scheduler} this operator will use.</dd>
Expand Down Expand Up @@ -14865,6 +14915,11 @@ public final Observable<Observable<T>> window(
* ObservableSource.
* <p>
* <img width="640" height="475" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window8.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} does not operate by default on a particular {@link Scheduler}.</dd>
Expand All @@ -14891,6 +14946,11 @@ public final <B> Observable<Observable<T>> window(ObservableSource<B> boundary)
* ObservableSource.
* <p>
* <img width="640" height="475" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window8.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down Expand Up @@ -14922,6 +14982,11 @@ public final <B> Observable<Observable<T>> window(ObservableSource<B> boundary,
* {@code closingIndicator} emits an item.
* <p>
* <img width="640" height="550" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window2.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down Expand Up @@ -14953,6 +15018,11 @@ public final <U, V> Observable<Observable<T>> window(
* {@code closingIndicator} emits an item.
* <p>
* <img width="640" height="550" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/window2.png" alt="">
* <p>
* Note that ignoring windows or subscribing later (i.e., on another thread) will result in
* so-called window abandonment where a window may not contain any elements. In this case, subsequent
* elements will be dropped until the condition for the next window boundary is satisfied. The behavior is
* a tradeoff for ensuring upstream cancellation can happen under some race conditions.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>This version of {@code window} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ void drain() {

if (emitted != requested.get()) {
emitted++;
downstream.onNext(w);
FlowableWindowSubscribeIntercept<T> intercept = new FlowableWindowSubscribeIntercept<T>(w);
downstream.onNext(intercept);
if (intercept.tryAbandon()) {
w.onComplete();
}
} else {
SubscriptionHelper.cancel(upstream);
boundarySubscriber.dispose();
Expand Down
Loading