Skip to content

2.x: coverage and cleanup 10/04-1 #4666

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
Oct 4, 2016
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
6 changes: 3 additions & 3 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2670,13 +2670,13 @@ public final Maybe<T> hide() {
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return an empty Maybe that only calls {@code onComplete} or {@code onError}, based on which one is
* @return an empty Completable that only calls {@code onComplete} or {@code onError}, based on which one is
* called by the source Maybe
* @see <a href="http://reactivex.io/documentation/operators/ignoreelements.html">ReactiveX operators documentation: IgnoreElements</a>
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final Maybe<T> ignoreElement() {
return RxJavaPlugins.onAssembly(new MaybeIgnoreElement<T>(this));
public final Completable ignoreElement() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return RxJavaPlugins.onAssembly(new MaybeIgnoreElementCompletable<T>(this));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public static boolean replace(AtomicReference<Disposable> field, Disposable d) {
}
}

/**
* Atomically disposes the Disposable in the field if not already disposed.
* @param field the target field
* @return true if the curren thread managed to dispose the Disposable
*/
public static boolean dispose(AtomicReference<Disposable> field) {
Disposable current = field.get();
Disposable d = DISPOSED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.reactivex.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.exceptions.*;
import io.reactivex.functions.Consumer;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.plugins.RxJavaPlugins;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void onError(Throwable t) {
consumer.accept(Notification.<Object>createOnError(t));
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
RxJavaPlugins.onError(ex);
RxJavaPlugins.onError(new CompositeException(t, ex));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,6 @@ void slowPath(long r) {

r = get();
if (e == r) {

if (cancelled) {
return;
}

boolean b;

try {
b = it.hasNext();
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
a.onError(ex);
return;
}

if (!b) {
if (!cancelled) {
a.onComplete();
}
return;
}

r = addAndGet(-e);
if (r == 0L) {
return;
Expand Down Expand Up @@ -423,28 +401,6 @@ void slowPath(long r) {

r = get();
if (e == r) {

if (cancelled) {
return;
}

boolean hasNext;

try {
hasNext = it.hasNext();
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
a.onError(ex);
return;
}

if (!hasNext) {
if (!cancelled) {
a.onComplete();
}
return;
}

r = addAndGet(-e);
if (r == 0L) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.reactivex.*;
import io.reactivex.Scheduler.Worker;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.exceptions.*;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.internal.fuseable.SimpleQueue;
import io.reactivex.internal.queue.MpscLinkedQueue;
Expand Down Expand Up @@ -126,7 +126,7 @@ public void onSubscribe(Subscription s) {
} else {
cancelled = true;
s.cancel();
a.onError(new IllegalStateException("Could not deliver first window due to lack of requests."));
a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests."));
return;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ void drainLoop() {
queue.clear();
s.cancel();
dispose();
a.onError(new IllegalStateException("Could not deliver first window due to lack of requests."));
a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests."));
return;
}
} else {
Expand Down Expand Up @@ -374,7 +374,7 @@ public void onSubscribe(Subscription s) {
} else {
cancelled = true;
s.cancel();
a.onError(new IllegalStateException("Could not deliver initial window due to lack of requests."));
a.onError(new MissingBackpressureException("Could not deliver initial window due to lack of requests."));
return;
}

Expand Down Expand Up @@ -436,7 +436,7 @@ public void onNext(T t) {
window = null;
s.cancel();
dispose();
actual.onError(new IllegalStateException("Could not deliver window due to lack of requests"));
actual.onError(new MissingBackpressureException("Could not deliver window due to lack of requests"));
return;
}
} else {
Expand Down Expand Up @@ -572,7 +572,7 @@ void drainLoop() {
queue.clear();
s.cancel();
dispose();
a.onError(new IllegalStateException("Could not deliver first window due to lack of requests."));
a.onError(new MissingBackpressureException("Could not deliver first window due to lack of requests."));
return;
}
}
Expand Down Expand Up @@ -613,7 +613,7 @@ void drainLoop() {
window = null;
s.cancel();
dispose();
actual.onError(new IllegalStateException("Could not deliver window due to lack of requests"));
actual.onError(new MissingBackpressureException("Could not deliver window due to lack of requests"));
return;
}
} else {
Expand Down Expand Up @@ -719,7 +719,7 @@ public void run() {

} else {
s.cancel();
actual.onError(new IllegalStateException("Could not emit the first window due to lack of requests"));
actual.onError(new MissingBackpressureException("Could not emit the first window due to lack of requests"));
}
}

Expand Down Expand Up @@ -878,7 +878,7 @@ public void run() {
}
}, timespan, unit);
} else {
a.onError(new IllegalStateException("Can't emit window due to lack of requests"));
a.onError(new MissingBackpressureException("Can't emit window due to lack of requests"));
continue;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,37 @@ public MaybeFromFuture(Future<? extends T> future, long timeout, TimeUnit unit)
protected void subscribeActual(MaybeObserver<? super T> observer) {
Disposable d = Disposables.empty();
observer.onSubscribe(d);
if (d.isDisposed()) {
return;
}

T v;
try {
if (timeout <= 0L) {
v = future.get();
} else {
v = future.get(timeout, unit);
}
} catch (InterruptedException ex) {
if (d.isDisposed()) {
if (!d.isDisposed()) {
T v;
try {
if (timeout <= 0L) {
v = future.get();
} else {
v = future.get(timeout, unit);
}
} catch (InterruptedException ex) {
if (!d.isDisposed()) {
observer.onError(ex);
}
return;
}
observer.onError(ex);
return;
} catch (ExecutionException ex) {
if (d.isDisposed()) {
} catch (ExecutionException ex) {
if (!d.isDisposed()) {
observer.onError(ex.getCause());
}
return;
}
observer.onError(ex.getCause());
return;
} catch (TimeoutException ex) {
if (d.isDisposed()) {
} catch (TimeoutException ex) {
if (!d.isDisposed()) {
observer.onError(ex);
}
return;
}
observer.onError(ex);
return;
}
if (d.isDisposed()) {
return;
}
if (v == null) {
observer.onComplete();
} else {
observer.onSuccess(v);
if (!d.isDisposed()) {
if (v == null) {
observer.onComplete();
} else {
observer.onSuccess(v);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.internal.operators.maybe;

import io.reactivex.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.internal.fuseable.FuseToMaybe;
import io.reactivex.plugins.RxJavaPlugins;

/**
* Turns an onSuccess into an onComplete, onError and onComplete is relayed as is.
*
* @param <T> the value type
*/
public final class MaybeIgnoreElementCompletable<T> extends Completable implements FuseToMaybe<T> {

final MaybeSource<T> source;

public MaybeIgnoreElementCompletable(MaybeSource<T> source) {
this.source = source;
}

@Override
protected void subscribeActual(CompletableObserver observer) {
source.subscribe(new IgnoreMaybeObserver<T>(observer));
}

@Override
public Maybe<T> fuseToMaybe() {
return RxJavaPlugins.onAssembly(new MaybeIgnoreElement<T>(source));
}

static final class IgnoreMaybeObserver<T> implements MaybeObserver<T>, Disposable {

final CompletableObserver actual;

Disposable d;

IgnoreMaybeObserver(CompletableObserver actual) {
this.actual = actual;
}

@Override
public void onSubscribe(Disposable d) {
if (DisposableHelper.validate(this.d, d)) {
this.d = d;

actual.onSubscribe(this);
}
}

@Override
public void onSuccess(T value) {
d = DisposableHelper.DISPOSED;
actual.onComplete();
}

@Override
public void onError(Throwable e) {
d = DisposableHelper.DISPOSED;
actual.onError(e);
}

@Override
public void onComplete() {
d = DisposableHelper.DISPOSED;
actual.onComplete();
}

@Override
public boolean isDisposed() {
return d.isDisposed();
}

@Override
public void dispose() {
d.dispose();
d = DisposableHelper.DISPOSED;
}

}

}
Loading