Skip to content

Add unawaited to package:meta. #33962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/meta/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.7

* Add `unawaited` to mark that a `Future` result is intentionally ignored,
silencing the `unawaited_futures` lint.

## 1.1.6

* Set max SDK version to <3.0.0.
Expand Down
14 changes: 7 additions & 7 deletions pkg/meta/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Annotations for Static Analysis

This package defines annotations that can be used by the tools that are shipped
with the Dart SDK.
This package defines annotations, and functions that act like annotations for
expressions, that can be used by the tools that are shipped with the Dart SDK.

## Library Structure

The annotations in this package are defined in two libraries.

The library in `meta.dart` defines annotations that can be used by static
analysis tools to provide a more complete analysis of the code that uses them.
Within the SDK, these tools include the command-line analyzer (`dartanalyzer`)
and the analysis server that is used to power many of the Dart-enabled
development tools.
The library in `meta.dart` defines annotations and functions that can be used
by static analysis tools to provide a more complete analysis of the code that
uses them. Within the SDK, these tools include the command-line analyzer
(`dartanalyzer`) and the analysis server that is used to power many of the
Dart-enabled development tools.

The library in `dart2js.dart` defines annotations that provide hints to dart2js
to improve the quality of the JavaScript code that it produces. These
Expand Down
22 changes: 22 additions & 0 deletions pkg/meta/lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/// in the language tour.
library meta;

import 'dart:async' show Future;

/// Used to annotate a function `f`. Indicates that `f` always throws an
/// exception. Any functions that override `f`, in class inheritence, are also
/// expected to conform to this contract.
Expand Down Expand Up @@ -244,6 +246,26 @@ class Required {
const Required([this.reason]);
}

/// Used to indicate to tools that [future] is intentionally not `await`-ed.
///
/// In an `async` context, it is normally expected than all [Future]s are
/// awaited, and that is the basis of the lint `unawaited_futures`. However,
/// there are times where one or more futures are intentionally not awaited.
/// This function may be used to ignore a particular future. It silences the
/// `unawaited_futures` lint.
///
/// ```
/// Future<void> saveUserPreferences() async {
/// await _writePreferences();
///
/// // While 'log' returns a Future, the consumer of 'saveUserPreferences'
/// // is unlikely to want to wait for that future to complete; they only
/// // care about the preferences being written).
/// unawaited(log('Preferences saved!'));
/// }
/// ```
void unawaited(Future<void> future) {}

class _AlwaysThrows {
const _AlwaysThrows();
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: meta
version: 1.1.6
version: 1.1.7
author: Dart Team <[email protected]>
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/meta
description: >
Expand Down