Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ if (project.hasProperty("releaseMode")) {
}
mavenPublishing {
// or when publishing to https://central.sonatype.com/
publishToMavenCentral(true, DeploymentValidation.PUBLISHED)
publishToMavenCentral(true, com.vanniktech.maven.publish.DeploymentValidation.PUBLISHED)

// signAllPublications()
}
Expand Down
29 changes: 16 additions & 13 deletions src/main/java/io/reactivex/rxjava4/disposables/Disposable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Represents a disposable resource.
*/
public interface Disposable extends AutoCloseable {
public interface Disposable {
/**
* Dispose the resource, the operation should be idempotent.
*/
Expand All @@ -37,14 +37,6 @@ public interface Disposable extends AutoCloseable {
*/
boolean isDisposed();

/**
* Dispose the resource, the operation should be idempotent.
* @since 4.0.0
*/
default void close() {
dispose();
}

/**
* Construct a {@code Disposable} by wrapping a {@link Runnable} that is
* executed exactly once when the {@code Disposable} is disposed.
Expand Down Expand Up @@ -75,9 +67,9 @@ static Disposable fromAction(@NonNull Action action) {

/**
* Construct a {@code Disposable} by wrapping a {@link Future} that is
* cancelled exactly once when the {@code Disposable} is disposed.
* canceled exactly once when the {@code Disposable} is disposed.
* <p>
* The {@code Future} is cancelled with {@code mayInterruptIfRunning == true}.
* The {@code Future} is canceled with {@code mayInterruptIfRunning == true}.
* @param future the {@code Future} to wrap
* @return the new {@code Disposable} instance
* @throws NullPointerException if {@code future} is {@code null}
Expand All @@ -92,7 +84,7 @@ static Disposable fromFuture(@NonNull Future<?> future) {

/**
* Construct a {@code Disposable} by wrapping a {@link Future} that is
* cancelled exactly once when the {@code Disposable} is disposed.
* canceled exactly once when the {@code Disposable} is disposed.
* @param future the {@code Future} to wrap
* @param allowInterrupt if true, the future cancel happens via {@code Future.cancel(true)}
* @return the new {@code Disposable} instance
Expand All @@ -107,7 +99,7 @@ static Disposable fromFuture(@NonNull Future<?> future, boolean allowInterrupt)

/**
* Construct a {@code Disposable} by wrapping a {@link Subscription} that is
* cancelled exactly once when the {@code Disposable} is disposed.
* canceled exactly once when the {@code Disposable} is disposed.
* @param subscription the {@code Runnable} to wrap
* @return the new {@code Disposable} instance
* @throws NullPointerException if {@code subscription} is {@code null}
Expand Down Expand Up @@ -147,6 +139,17 @@ static AutoCloseable toAutoCloseable(@NonNull Disposable disposable) {
return disposable::dispose;
}

/**
* Wraps this {@code Disposable} into an {@link AutoCloseable} instance
* that can be used with try-with-resources constructs.
* @return the new {@code AutoCloseable} instance
* @since 4.0.0
*/
@NonNull
default AutoCloseable asAutoCloseable() {
return this::dispose;
}

/**
* Returns a new, non-disposed {@code Disposable} instance.
* @return a new, non-disposed {@code Disposable} instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ default Disposable subscribe(Disposable d) {
* cases where the dispose signal has no side effects to work with.
* @since 4.0.0
*/
static DisposableContainer NEVER = new NeverDisposableContainer();
DisposableContainer NEVER = new NeverDisposableContainer();

/**
* Implementation of a never disposable container.
* @since 4.0.0
*/
static record NeverDisposableContainer() implements DisposableContainer {
record NeverDisposableContainer() implements DisposableContainer {

@Override
public void dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ protected void subscribeActual(Subscriber<? super T> s) {
}
}

@SuppressWarnings("resource")
void cancel(RefConnection rc) {
SequentialDisposable sd;
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void subscribeActual(Observer<? super T> observer) {
return;
}

@SuppressWarnings("resource")
AmbCoordinator<T> ac = new AmbCoordinator<>(observer, count);
ac.subscribe(sources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void subscribeActual(Observer<? super R> observer) {
return;
}

@SuppressWarnings("resource")
LatestCoordinator<T, R> lc = new LatestCoordinator<>(observer, combiner, count, bufferSize, delayError);
lc.subscribe(sources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ protected void subscribeActual(Observer<? super T> observer) {
}
}

@SuppressWarnings("resource")
void cancel(RefConnection rc) {
SequentialDisposable sd;
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void subscribeActual(Observer<? super R> observer) {
return;
}

@SuppressWarnings("resource")
ZipCoordinator<T, R> zc = new ZipCoordinator<>(observer, zipper, count, delayError);
zc.subscribe(sources, bufferSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public Disposable schedule(@NonNull Runnable run) {
task = interruptibleTask;
disposable = interruptibleTask;
} else {
@SuppressWarnings("resource")
BooleanRunnable runnableTask = new BooleanRunnable(decoratedRun);

task = runnableTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public Disposable schedule(@NonNull Runnable run) {
task = interruptibleTask;
disposable = interruptibleTask;
} else {
@SuppressWarnings("resource")
BooleanRunnable runnableTask = new BooleanRunnable(decoratedRun);

task = runnableTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ static <T> T await(@NonNull CompletionStage<T> stage, @Nullable DisposableContai
return f.join();
}
var d = Disposable.fromFuture(f, true);
try (var _ = canceller.subscribe(d)) {
return f.join();
}
canceller.subscribe(d);
return f.join();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Void call() {
var w = worker;
worker = null;
if (w != null) {
w.close();
w.dispose();
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void cancel() {
var w = worker;
worker = null;
if (w != null) {
w.close();
w.dispose();
}
} finally {
producerReady.resume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ public void onError(Throwable e) {
public void timerCancel() throws InterruptedException {
Completable c = Completable.timer(250, TimeUnit.MILLISECONDS);

@SuppressWarnings("resource")
final SequentialDisposable sd = new SequentialDisposable();
final AtomicInteger calls = new AtomicInteger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void runnableThrows() throws Throwable {

Scheduler.Worker worker = Schedulers.single().createWorker();

@SuppressWarnings("resource")
DisposeTask task = new DisposeTask(() -> {
throw new TestException();
}, worker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void runnableThrows() {
try {
Scheduler.Worker worker = Schedulers.single().createWorker();

@SuppressWarnings("resource")
PeriodicDirectTask task = new PeriodicDirectTask(() -> {
throw new TestException();
}, worker);
Expand Down
Loading
Loading