-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.customer-google3devexp-pkg-metaIssues related to package:metaIssues related to package:metatype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
AngularDart and ACX have lifecycle events that are added via implements:
abstract class OnDestroy {
/// Implement to receive a notification when the component is being removed.
///
/// This is an ideal time to cleanup streams, cancel pending RPCs, clear caches, etc.
void ngOnDestroy();
}A frequently observed problem is users wanting to use await, so they add async:
class MyComp implements OnDestroy {
StreamSubscription<void> _windowResizeSub;
@override
void ngOnDestroy() async {
await doSomethingAsync();
// The user might continue to receive window.onResize events after the component has been
// effectively destroyed because they used "await" above instead of just "doSomethingAsync()".
_windowResizeSub.cancel();
}
}... and this has been exasperated by allowing async on void methods unfortunately.
We would like a metadata annotation discouraging any use of async / await on certain methods:
import 'package:meta/meta.dart';
abstract class OnDestroy {
/// Implement to receive a notification when the component is being removed.
///
/// This is an ideal time to cleanup streams, cancel pending RPCs, clear caches, etc.
@mustBeSynchronous
void ngOnDestroy();
}
class MyComp implements OnDestroy {
StreamSubscription<void> _windowResizeSub;
@override
// LINT: "OnDestroy.ngOnDestroy should not use async/await"
void ngOnDestroy() async {
await doSomethingAsync();
}
}/cc @srawlins
greglittlefield-wf
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.customer-google3devexp-pkg-metaIssues related to package:metaIssues related to package:metatype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug