-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
2.x: Improve coverage & related cleanup 03/05 #5891
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -526,36 +526,16 @@ static final class InnerSubscription<T> extends AtomicLong implements Subscripti | |
public void request(long n) { | ||
// ignore negative requests | ||
if (SubscriptionHelper.validate(n)) { | ||
// In general, RxJava doesn't prevent concurrent requests (with each other or with | ||
// a cancel) so we need a CAS-loop, but we need to handle | ||
// request overflow and cancelled/not requested state as well. | ||
for (;;) { | ||
// get the current request amount | ||
long r = get(); | ||
// if child called cancel() do nothing | ||
if (r == CANCELLED) { | ||
return; | ||
} | ||
// ignore zero requests except any first that sets in zero | ||
if (r >= 0L && n == 0) { | ||
return; | ||
} | ||
// otherwise, increase the request count | ||
long u = BackpressureHelper.addCap(r, n); | ||
|
||
// try setting the new request value | ||
if (compareAndSet(r, u)) { | ||
// increment the total request counter | ||
BackpressureHelper.add(totalRequested, n); | ||
// if successful, notify the parent dispatcher this child can receive more | ||
// elements | ||
parent.manageRequests(); | ||
|
||
parent.buffer.replay(this); | ||
return; | ||
} | ||
// otherwise, someone else changed the state (perhaps a concurrent | ||
// request or cancellation) so retry | ||
// add to the current requested and cap it at MAX_VALUE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was one of the earliest v2 operators where the infrastructure lacked the |
||
// except when there was a concurrent cancellation | ||
if (BackpressureHelper.addCancel(this, n) != CANCELLED) { | ||
// increment the total request counter | ||
BackpressureHelper.add(totalRequested, n); | ||
// if successful, notify the parent dispatcher this child can receive more | ||
// elements | ||
parent.manageRequests(); | ||
// try replaying any cached content | ||
parent.buffer.replay(this); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,8 +93,8 @@ public void onComplete() { | |
completeMain(); | ||
} | ||
|
||
boolean setOther(Subscription o) { | ||
return SubscriptionHelper.setOnce(other, o); | ||
void setOther(Subscription o) { | ||
SubscriptionHelper.setOnce(other, o, Long.MAX_VALUE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is always |
||
} | ||
|
||
@Override | ||
|
@@ -150,9 +150,7 @@ static final class SamplerSubscriber<T> implements FlowableSubscriber<Object> { | |
|
||
@Override | ||
public void onSubscribe(Subscription s) { | ||
if (parent.setOther(s)) { | ||
s.request(Long.MAX_VALUE); | ||
} | ||
parent.setOther(s); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import io.reactivex.*; | ||
import io.reactivex.disposables.*; | ||
import io.reactivex.exceptions.Exceptions; | ||
|
||
/** | ||
* Waits until the source Future completes or the wait times out; treats a {@code null} | ||
|
@@ -50,17 +51,11 @@ protected void subscribeActual(MaybeObserver<? super T> observer) { | |
} else { | ||
v = future.get(timeout, unit); | ||
} | ||
} catch (InterruptedException ex) { | ||
if (!d.isDisposed()) { | ||
observer.onError(ex); | ||
} | ||
return; | ||
} catch (ExecutionException ex) { | ||
if (!d.isDisposed()) { | ||
observer.onError(ex.getCause()); | ||
} catch (Throwable ex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reduce the code duplication to one catch and extract the actual |
||
if (ex instanceof ExecutionException) { | ||
ex = ex.getCause(); | ||
} | ||
return; | ||
} catch (TimeoutException ex) { | ||
Exceptions.throwIfFatal(ex); | ||
if (!d.isDisposed()) { | ||
observer.onError(ex); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
import io.reactivex.*; | ||
import io.reactivex.disposables.Disposable; | ||
import io.reactivex.internal.disposables.DisposableHelper; | ||
|
||
public final class ObservableSkip<T> extends AbstractObservableWithUpstream<T, T> { | ||
final long n; | ||
|
@@ -40,9 +41,11 @@ static final class SkipObserver<T> implements Observer<T>, Disposable { | |
} | ||
|
||
@Override | ||
public void onSubscribe(Disposable s) { | ||
this.d = s; | ||
actual.onSubscribe(this); | ||
public void onSubscribe(Disposable d) { | ||
if (DisposableHelper.validate(this.d, d)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation was missing. |
||
this.d = d; | ||
actual.onSubscribe(this); | ||
} | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ static final class OtherObserver<T, U> | |
|
||
@Override | ||
public void onSubscribe(Disposable d) { | ||
if (DisposableHelper.set(this, d)) { | ||
if (DisposableHelper.setOnce(this, d)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have been |
||
|
||
actual.onSubscribe(this); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the
request
call comes directly aftersetOnce
, they can be combined into one and this resolves a lot of partial coverage cases.