|
1 |
| -// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 1 | +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a
|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
5 |
| -/// Constants for use in metadata annotations. |
| 5 | +/// Constants and functions that developers can use to express the intentions |
| 6 | +/// that otherwise can't be deduced by statically analyzing the source code. |
6 | 7 | ///
|
7 | 8 | /// See also `@deprecated` and `@override` in the `dart:core` library.
|
8 | 9 | ///
|
|
12 | 13 | /// function's name differently.
|
13 | 14 | ///
|
14 | 15 | /// For information on installing and importing this library, see the [meta
|
15 |
| -/// package on pub.dev](https://pub.dev/packages/meta). For examples of using |
| 16 | +/// package on pub.dev](https://pub.dev/packages/meta). For examples of using |
16 | 17 | /// annotations, see
|
17 | 18 | /// [Metadata](https://dart.dev/guides/language/language-tour#metadata) in the
|
18 | 19 | /// language tour.
|
@@ -266,6 +267,26 @@ const _VisibleForOverriding visibleForOverriding = _VisibleForOverriding();
|
266 | 267 | /// library which is in the `test` folder of the defining package.
|
267 | 268 | const _VisibleForTesting visibleForTesting = _VisibleForTesting();
|
268 | 269 |
|
| 270 | +/// Indicates to tools that [future] is intentionally not `await`-ed. |
| 271 | +/// |
| 272 | +/// In an `async` context, it is normally expected that all [Future]s are |
| 273 | +/// awaited, and that is the basis of the lint `unawaited_futures`. However, |
| 274 | +/// there are times where one or more futures are intentionally not awaited. |
| 275 | +/// This function may be used to ignore a particular future. It silences the |
| 276 | +/// `unawaited_futures` lint. |
| 277 | +/// |
| 278 | +/// ``` |
| 279 | +/// Future<void> saveUserPreferences() async { |
| 280 | +/// await _writePreferences(); |
| 281 | +/// |
| 282 | +/// // While 'log' returns a Future, the consumer of 'saveUserPreferences' |
| 283 | +/// // is unlikely to want to wait for that future to complete; they only |
| 284 | +/// // care about the preferences being written). |
| 285 | +/// unawaited(log('Preferences saved!')); |
| 286 | +/// } |
| 287 | +/// ``` |
| 288 | +void unawaited(Future<void>? future) {} |
| 289 | + |
269 | 290 | /// Used to annotate a class.
|
270 | 291 | ///
|
271 | 292 | /// See [immutable] for more details.
|
|
0 commit comments