Skip to content

Commit 9c5f994

Browse files
Merge pull request #15 from Workiva/rap-1455_add-isDisposing
RAP-1455 Add isDisposing and isDisposedOrDisposing
2 parents 86ec0ef + 57c0783 commit 9c5f994

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@
1313

1414
### Semantic Versioning
1515

16-
> **This library is still pre-1.0.0.**
17-
>
18-
> Patches and minor changes will be released in a patch version, while breaking
19-
> changes can be released in a minor version.
20-
2116
- [ ] **Patch**
2217
- [ ] This change does not affect the public API
2318
- [ ] This change fixes existing incorrect behavior without any additions
19+
- [ ] **Minor**
2420
- [ ] This change adds something to the public API
2521
- [ ] This change deprecates a part of the public API
26-
- [ ] **Minor**
22+
* [ ] Major
2723
- [ ] This change modifies part of the public API in a backwards-incompatible manner
2824
- [ ] This change removes part of the public API
2925

30-
3126
### Testing/QA
3227

3328
- [ ] CI passes
3429

35-
3630
### Code Review
3731

38-
@dustinlessard-wf @evanweible-wf @jayudey-wf @maxwellpeterson-wf @sebastianmalysa-wf @trentgrover-wf
32+
@dustinlessard-wf
33+
@evanweible-wf
34+
@jayudey-wf
35+
@maxwellpeterson-wf
36+
@sebastianmalysa-wf
37+
@trentgrover-wf
38+

lib/disposable.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ abstract class Disposable implements _Disposable {
113113
/// Whether this object has been disposed.
114114
bool get isDisposed => _didDispose.isCompleted;
115115

116+
/// Whether this object has been disposed or is disposing.
117+
///
118+
/// This will become `true` as soon as the [dispose] method is called
119+
/// and will remain `true` forever. This is intended as a convenience
120+
/// and `object.isDisposedOrDisposing` will always be the same as
121+
/// `object.isDisposed || object.isDisposing`.
122+
bool get isDisposedOrDisposing => isDisposed || isDisposing;
123+
124+
/// Whether this object is in the process of being disposed.
125+
///
126+
/// This will become `true` as soon as the [dispose] method is called
127+
/// and will become `false` once the [didDispose] future completes.
128+
bool get isDisposing => _isDisposing;
129+
116130
/// Dispose of the object, cleaning up to prevent memory leaks.
117131
@override
118132
Future<Null> dispose() async {
@@ -191,6 +205,7 @@ abstract class Disposable implements _Disposable {
191205

192206
Null _completeDisposeFuture(List<dynamic> _) {
193207
_didDispose.complete();
208+
_isDisposing = false;
194209
return null;
195210
}
196211

test/unit/vm/disposable_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,18 @@ class DisposableThing extends Object with Disposable {
4040

4141
@override
4242
Future<Null> onDispose() {
43+
expect(isDisposed, isFalse);
44+
expect(isDisposing, isTrue);
45+
expect(isDisposedOrDisposing, isTrue);
4346
wasOnDisposeCalled = true;
44-
return new Future(() {});
47+
var future = new Future<Null>(() => null);
48+
future.then((_) async {
49+
await new Future(() {}); // Give it a chance to update state.
50+
expect(isDisposed, isTrue);
51+
expect(isDisposing, isFalse);
52+
expect(isDisposedOrDisposing, isTrue);
53+
});
54+
return future;
4555
}
4656
}
4757

0 commit comments

Comments
 (0)