Skip to content

Commit

Permalink
rename disposed extension methods to disposedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 31, 2022
1 parent 95d358f commit ad31859
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/dispose_scope/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import 'package:dispose_scope/dispose_scope.dart';
final disposeScope = DisposeScope();
// StreamSubscription will be cancelled when disposeScope is disposed
const Stream.empty().listen((event) {}).disposed(disposeScope);
const Stream.empty().listen((event) {}).disposedBy(disposeScope);
// Timer will be cancelled when disposeScope is disposed
Timer(Duration.zero, () {}).disposed(disposeScope);
Timer(Duration.zero, () {}).disposedBy(disposeScope);
disposeScope.dispose();
```
Expand Down
4 changes: 2 additions & 2 deletions packages/dispose_scope/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ void main() {
final disposeScope = DisposeScope();

// StreamSubscription will be cancelled when disposeScope is disposed
const Stream<void>.empty().listen((dynamicevent) {}).disposed(disposeScope);
const Stream<void>.empty().listen((dynamicevent) {}).disposedBy(disposeScope);

// Timer will be cancelled when disposeScope is disposed
Timer(Duration.zero, () {}).disposed(disposeScope);
Timer(Duration.zero, () {}).disposedBy(disposeScope);

disposeScope.dispose();
}
2 changes: 1 addition & 1 deletion packages/dispose_scope/lib/src/disposable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:dispose_scope/dispose_scope.dart';
/// An object that can be disposed.
abstract class Disposable {
/// Adds this object to [disposeScope].
void disposed(DisposeScope disposeScope) {
void disposedBy(DisposeScope disposeScope) {
disposeScope.addDispose(dispose);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension ConnectionTaskDisposed on ConnectionTask {
/// Adds this connection task to [disposeScope].
///
/// It will be canceled when [disposeScope] is disposed.
void disposed(DisposeScope disposeScope) {
void disposedBy(DisposeScope disposeScope) {
disposeScope.addDispose(() async => cancel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension DisposeScopeDisposed on DisposeScope {
/// Adds this dispose scope to [parentDisposeScope].
///
/// It will be disposed when [parentDisposeScope] is disposed.
void disposed(DisposeScope parentDisposeScope) {
void disposedBy(DisposeScope parentDisposeScope) {
if (parentDisposeScope == this) {
throw Exception(
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension ProcessDisposed on Process {
/// Adds this process to [disposeScope].
///
/// It will be killed when [disposeScope] is disposed.
void disposed(DisposeScope disposeScope) {
void disposedBy(DisposeScope disposeScope) {
disposeScope.addDispose(() async => kill());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extension SinkDisposed on Sink {
/// Adds this sink to [disposeScope].
///
/// It will be closed when [disposeScope] is disposed.
void disposed(DisposeScope disposeScope) {
void disposedBy(DisposeScope disposeScope) {
disposeScope.addDispose(() async => close());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension StreamSubscriptionDisposed on StreamSubscription {
/// Adds this stream subscription to [disposeScope].
///
/// It will be canceled when [disposeScope] is disposed.
void disposed(DisposeScope disposeScope) {
void disposedBy(DisposeScope disposeScope) {
disposeScope.addDispose(() async => cancel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension TimerDisposed on Timer {
/// Adds this timer to [disposeScope].
///
/// It will be canceled when [disposeScope] is disposed.
void disposed(DisposeScope disposeScope) {
void disposedBy(DisposeScope disposeScope) {
disposeScope.addDispose(() async => cancel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
test(
'adds Dispose to DisposeScope when disposed is called',
() async {
connectionTask.disposed(scope);
connectionTask.disposedBy(scope);

await scope.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void main() {
test(
'adds Dispose to DisposeScope when disposed is called',
() async {
disposeScope.disposed(scope);
disposeScope.disposedBy(scope);

await scope.dispose();

Expand All @@ -35,7 +35,7 @@ void main() {
test(
'throws Exception when disposed is called with the same store',
() async {
expect(() => disposeScope.disposed(disposeScope), throwsException);
expect(() => disposeScope.disposedBy(disposeScope), throwsException);
},
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void main() {
test(
'adds Dispose to DisposeScope when disposed is called',
() async {
sink.disposed(scope);
sink.disposedBy(scope);

await scope.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
test(
'adds Dispose to DisposeScope when disposed is called',
() async {
streamSubscription.disposed(scope);
streamSubscription.disposedBy(scope);

await scope.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
test(
'adds Dispose to DisposeScope when disposed is called',
() async {
timer.disposed(scope);
timer.disposedBy(scope);

await scope.dispose();

Expand Down

0 comments on commit ad31859

Please sign in to comment.