Skip to content

Commit

Permalink
Add note about unawaited futures (#3562)
Browse files Browse the repository at this point in the history
Fixes #1250
  • Loading branch information
kwalrath authored Sep 9, 2021
1 parent 095d0bf commit a6e1e1b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/_guides/language/language-tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,8 @@ looks similar to synchronous code.
When you need the result of a completed Future,
you have two options:

* Use `async` and `await`.
* Use `async` and `await`, as described here and in the
[asynchronous programming codelab](/codelabs/async-await).
* Use the Future API, as described
[in the library tour](/guides/libraries/library-tour#future).

Expand Down Expand Up @@ -4149,6 +4150,20 @@ Future<void> main() [!async!] {
}
{% endprettify %}

{{site.alert.note}}
The preceding example uses an `async` function (`checkVersion()`)
without waiting for a result —
a practice that can cause problems
if the code assumes that the function has finished executing.
To avoid this problem,
use the [unawaited_futures linter rule][].
{{site.alert.end}}

[unawaited_futures linter rule]: /tools/linter-rules#unawaited_futures

For an interactive introduction to using futures, `async`, and `await`,
see the [asynchronous programming codelab](/codelabs/async-await).


<a id="async"></a>
### Declaring async functions
Expand Down

0 comments on commit a6e1e1b

Please sign in to comment.