Skip to content

Commit 74ae904

Browse files
authored
Chit.isDisposed() now returns true before calling the runWhenDisposed callbacks. (#3)
1 parent 0fd850a commit 74ae904

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# DurianRx releases
22

33
## [Unreleased]
4+
### Fixed
5+
* `Chit.isDisposed()` now returns true before calling the `runWhenDisposed` callbacks.
46

57
## [3.0.1] - 2019-11-12
68
* RxExecutor is now more consistent about failure - if the `onSuccess` throws an exception, it will always be passed to the `onFailure` handler as a `CompletionException`.

src/main/java/com/diffplug/common/rx/Chit.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.reactivex.disposables.Disposable;
2020
import java.util.ArrayList;
21+
import java.util.List;
2122

2223
/**
2324
* Makes it possible to receive a notification when a resource is disposed.
@@ -34,9 +35,8 @@
3435
public interface Chit {
3536
/**
3637
* Returns whether the resource is disposed. May be called from any thread,
37-
* and may suffer from glitches, but only of the kind where the resource is
38-
* actually disposed but this method incorrectly returns false due to a threading
39-
* glitch which will eventually be resolved.
38+
* and must return true as soon as `dispose()` is called, no matter which thread
39+
* `dispose()` was called from.
4040
*/
4141
boolean isDisposed();
4242

@@ -73,11 +73,15 @@ public final class Settable implements Chit, Disposable {
7373
private Settable() {}
7474

7575
@Override
76-
public synchronized void dispose() {
77-
if (runWhenDisposed != null) {
78-
runWhenDisposed.forEach(Runnable::run);
76+
public void dispose() {
77+
List<Runnable> toDispose;
78+
synchronized (this) {
79+
toDispose = runWhenDisposed;
7980
runWhenDisposed = null;
8081
}
82+
if (toDispose != null) {
83+
toDispose.forEach(Runnable::run);
84+
}
8185
}
8286

8387
@Override

0 commit comments

Comments
 (0)