CINXE.COM
dart:async | Dart
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><script>!function(e,t,a,n){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a);m.async=!0,m.src="https://www.googletagmanager.com/gtm.js?id=GTM-5VSZM5J",g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer")</script><meta name="description" content="Learn about the major features in Dart's dart:async library."><title>dart:async | Dart</title><link rel="icon" sizes="64x64" href="/assets/img/logo/dart-64.png" eleventy:ignore><link href="/assets/img/touch-icon-iphone.png" rel="apple-touch-icon" eleventy:ignore><link href="/assets/img/touch-icon-ipad.png" rel="apple-touch-icon" sizes="152x152" eleventy:ignore><link href="/assets/img/touch-icon-iphone-retina.png" rel="apple-touch-icon" sizes="180x180" eleventy:ignore><link href="/assets/img/touch-icon-ipad-retina.png" rel="apple-touch-icon" sizes="167x167" eleventy:ignore><meta name="twitter:card" content="summary"><meta name="twitter:site" content="@dart_lang"><meta name="twitter:title" content="dart:async"><meta name="twitter:description" content="Learn about the major features in Dart's dart:async library."><meta property="og:title" content="dart:async"><meta property="og:description" content="Learn about the major features in Dart's dart:async library."><meta property="og:url" content="/libraries/dart-async/"><meta property="og:image" content="/assets/img/logo/dart-logo-for-shares.png?2" eleventy:ignore><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Display:wght@400&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Mono:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet"><link rel="stylesheet" href="/assets/css/main.css"><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.5/js.cookie.min.js" integrity="sha512-nlp9/l96/EpjYBx7EP7pGASVXNe80hGhYAUrjeXnu/fyF5Py0/RXav4BBNs7n5Hx1WFhOEOWSAVjGeC3oKxDVQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="/assets/js/os-tabs.js"></script><script src="/assets/js/utilities.js"></script><script src="/assets/js/main.js"></script><script>!function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src="//www.google-analytics.com/analytics.js",s.parentNode.insertBefore(o,s)}(window,document,"script",0,"ga"),ga("create","UA-26406144-4","auto"),ga("send","pageview")</script></head><body class="default.html show_banner"><a id="skip" href="#site-content-title">Skip to main content</a><section id="cookie-notice"><div class="container"><p>dart.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic. <a href="https://policies.google.com/technologies/cookies" target="_blank" rel="noopener">Learn more</a>.</p><button id="cookie-consent" class="btn btn-primary">OK, got it</button></div></section><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5VSZM5J" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><header id="page-header" class="site-header"><nav id="mainnav" class="site-header"><div id="menu-toggle"><i class="material-symbols">menu</i></div><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart"></a><ul class="navbar"><li><a href="/overview" class="nav-link">Overview</a></li><li class="mainnav__get-started"><a href="/guides" class="nav-link active"><span>Docs</span></a></li><li><a href="/community" class="nav-link">Community</a></li><li><a href="/#try-dart" class="nav-link">Try Dart</a></li><li><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="searchfield"><form action="/search" class="site-header__search form-inline" id="cse-search-box"><input type="hidden" name="cx" value="011220921317074318178:_yy-tmb5t_i"> <input type="hidden" name="ie" value="UTF-8"> <input type="hidden" name="hl" value="en"> <input class="site-header__searchfield form-control search-field" type="search" name="q" id="search-main" autocomplete="off" placeholder="Search" aria-label="Search"></form></li></ul></nav></header><div class="banner"><p class="banner__text">Announcing Dart 3.5 and an updated Dart roadmap! <a href="https://medium.com/dartlang/dart-3-5-6ca36259fa2f" target="_blank">Learn more</a></p></div><div id="sidenav"><form action="/search/" class="site-header__search form-inline"><input class="site-header__searchfield form-control search-field" type="search" name="q" id="search-side" autocomplete="off" placeholder="Search" aria-label="Search"></form><div class="site-sidebar"><ul class="navbar-nav"><li class="nav-item"><a href="/overview" class="nav-link">Overview</a></li><li class="nav-item"><a href="/community" class="nav-link">Community</a></li><li class="nav-item"><a href="https://dartpad.dev" class="nav-link">Try Dart</a></li><li class="nav-item"><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="nav-item"><a href="/guides" class="nav-link">Docs</a></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li></ul><ul class="nav flex-column"><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-1" role="button" aria-expanded="false" aria-controls="sidenav-1">Language</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1"><li class="nav-item"><a class="nav-link" href="/language">Introduction</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-2" href="#sidenav-1-2" role="button" aria-expanded="false" aria-controls="sidenav-1-2">Syntax basics</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-2"><li class="nav-item"><a class="nav-link" href="/language/variables">Variables</a></li><li class="nav-item"><a class="nav-link" href="/language/operators">Operators</a></li><li class="nav-item"><a class="nav-link" href="/language/comments">Comments</a></li><li class="nav-item"><a class="nav-link" href="/language/metadata">Metadata</a></li><li class="nav-item"><a class="nav-link" href="/language/libraries">Libraries & imports</a></li><li class="nav-item"><a class="nav-link" href="/language/keywords">Keywords</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-3" href="#sidenav-1-3" role="button" aria-expanded="false" aria-controls="sidenav-1-3">Types</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-3"><li class="nav-item"><a class="nav-link" href="/language/built-in-types">Built-in types</a></li><li class="nav-item"><a class="nav-link" href="/language/records">Records</a></li><li class="nav-item"><a class="nav-link" href="/language/collections">Collections</a></li><li class="nav-item"><a class="nav-link" href="/language/generics">Generics</a></li><li class="nav-item"><a class="nav-link" href="/language/typedefs">Typedefs</a></li><li class="nav-item"><a class="nav-link" href="/language/type-system">Type system</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-4" href="#sidenav-1-4" role="button" aria-expanded="false" aria-controls="sidenav-1-4">Patterns</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-4"><li class="nav-item"><a class="nav-link" href="/language/patterns">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/pattern-types">Pattern types</a></li><li class="nav-item"><a class="nav-link" href="https://codelabs.developers.google.com/codelabs/dart-patterns-records" target="_blank" rel="noopener">Applied tutorial</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/language/functions">Functions</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-6" href="#sidenav-1-6" role="button" aria-expanded="false" aria-controls="sidenav-1-6">Control flow</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-6"><li class="nav-item"><a class="nav-link" href="/language/loops">Loops</a></li><li class="nav-item"><a class="nav-link" href="/language/branches">Branches</a></li><li class="nav-item"><a class="nav-link" href="/language/error-handling">Error handling</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-7" href="#sidenav-1-7" role="button" aria-expanded="false" aria-controls="sidenav-1-7">Classes & objects</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-7"><li class="nav-item"><a class="nav-link" href="/language/classes">Classes</a></li><li class="nav-item"><a class="nav-link" href="/language/constructors">Constructors</a></li><li class="nav-item"><a class="nav-link" href="/language/methods">Methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extend">Extend a class</a></li><li class="nav-item"><a class="nav-link" href="/language/mixins">Mixins</a></li><li class="nav-item"><a class="nav-link" href="/language/enums">Enums</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-methods">Extension methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-types">Extension types</a></li><li class="nav-item"><a class="nav-link" href="/language/callable-objects">Callable objects</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-8" href="#sidenav-1-8" role="button" aria-expanded="false" aria-controls="sidenav-1-8">Class modifiers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-8"><li class="nav-item"><a class="nav-link" href="/language/class-modifiers">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/class-modifiers-for-apis">Class modifiers for API maintainers</a></li><li class="nav-item"><a class="nav-link" href="/language/modifier-reference">Reference</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-9" href="#sidenav-1-9" role="button" aria-expanded="false" aria-controls="sidenav-1-9">Concurrency</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-9"><li class="nav-item"><a class="nav-link" href="/language/concurrency">Overview</a></li><li class="nav-item"><a class="nav-link" href="/language/async">Asynchronous support</a></li><li class="nav-item"><a class="nav-link" href="/language/isolates">Isolates</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-10" href="#sidenav-1-10" role="button" aria-expanded="false" aria-controls="sidenav-1-10">Null safety</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-10"><li class="nav-item"><a class="nav-link" href="/null-safety">Sound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/migration-guide">Migrating to null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/understanding-null-safety">Understanding null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/unsound-null-safety">Unsound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/faq">FAQ</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" href="#sidenav-2" role="button" aria-expanded="true" aria-controls="sidenav-2">Core libraries</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-2"><li class="nav-item"><a class="nav-link" href="/libraries">Overview</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-core">dart:core</a></li><li class="nav-item"><a class="nav-link active" href="/libraries/dart-async">dart:async</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-math">dart:math</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-convert">dart:convert</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-io">dart:io</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-html">dart:html</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/libraries/collections/iterables">Iterable collections</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-2-10" href="#sidenav-2-10" role="button" aria-expanded="false" aria-controls="sidenav-2-10">Asynchronous programming</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2-10"><li class="nav-item"><a class="nav-link" href="/libraries/async/async-await">Tutorial</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/futures-error-handling">Futures and error handling</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/using-streams">Using streams</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/creating-streams">Creating streams</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-3" role="button" aria-expanded="false" aria-controls="sidenav-3">Effective Dart</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-3"><li class="nav-item"><a class="nav-link" href="/effective-dart">Overview</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/style">Style</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/documentation">Documentation</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/design">Design</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-4" role="button" aria-expanded="false" aria-controls="sidenav-4">Packages</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4"><li class="nav-item"><a class="nav-link" href="/tools/pub/packages">How to use packages</a></li><li class="nav-item"><a class="nav-link" href="/resources/useful-packages">Commonly used packages</a></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/create-packages">Creating packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/publishing">Publishing packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/writing-package-pages">Writing package pages</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-4-6" href="#sidenav-4-6" role="button" aria-expanded="false" aria-controls="sidenav-4-6">Package reference</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4-6"><li class="nav-item"><a class="nav-link" href="/tools/pub/dependencies">Dependencies</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/package-layout">Package layout conventions</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/environment-variables">Pub environment variables</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/pubspec">Pubspec file</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/troubleshoot">Troubleshooting pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/verified-publishers">Verified publishers</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/security-advisories">Security advisories</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/versioning">Versioning</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/custom-package-repositories">Custom package repositories</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/private-files">What not to commit</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-5" role="button" aria-expanded="false" aria-controls="sidenav-5">Development</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5"><li class="nav-item"><a class="nav-link" href="/guides/json">JSON</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/numbers">Number representation</a></li><li class="nav-item"><a class="nav-link" href="/resources/google-apis">Google APIs</a></li><li class="nav-item"><a class="nav-link" href="/multiplatform-apps">Multi-platform apps</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-5" href="#sidenav-5-5" role="button" aria-expanded="false" aria-controls="sidenav-5-5">Command-line & server apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-5"><li class="nav-item"><a class="nav-link" href="/server">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/cmdline">Write command-line apps</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/fetch-data">Fetch data from the internet</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/httpserver">Write HTTP servers</a></li><li class="nav-item"><a class="nav-link" href="/server/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/server/google-cloud">Google Cloud</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-6" href="#sidenav-5-6" role="button" aria-expanded="false" aria-controls="sidenav-5-6">Web apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-6"><li class="nav-item"><a class="nav-link" href="/web">Overview</a></li><li class="nav-item"><a class="nav-link" href="/web/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/web/deployment">Deployment</a></li><li class="nav-item"><a class="nav-link" href="/web/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/web/wasm">Wasm compilation</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/environment-declarations">Environment declarations</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-6" role="button" aria-expanded="false" aria-controls="sidenav-6">Interoperability</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6"><li class="nav-item"><a class="nav-link" href="/interop/c-interop">C interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/objective-c-interop">Objective-C & Swift interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/java-interop">Java & Kotlin interop</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-6-4" href="#sidenav-6-4" role="button" aria-expanded="false" aria-controls="sidenav-6-4">JavaScript interop</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6-4"><li class="nav-item"><a class="nav-link" href="/interop/js-interop">Overview</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/js-types">JS types</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/tutorials">Tutorials</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/past-js-interop">Past JS interop</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/interop/js-interop/package-web">Web interop</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-7" role="button" aria-expanded="false" aria-controls="sidenav-7">Tools & techniques</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7"><li class="nav-item"><a class="nav-link" href="/tools">Overview</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2" href="#sidenav-7-2" role="button" aria-expanded="false" aria-controls="sidenav-7-2">Editors & debuggers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2"><li class="nav-item"><a class="nav-link" href="/tools/jetbrains-plugin">IntelliJ & Android Studio</a></li><li class="nav-item"><a class="nav-link" href="/tools/vs-code">VS Code</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-devtools">Dart DevTools</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2-4" href="#sidenav-7-2-4" role="button" aria-expanded="false" aria-controls="sidenav-7-2-4">DartPad</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2-4"><li class="nav-item"><a class="nav-link" href="/tools/dartpad">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartpad/troubleshoot">Troubleshooting DartPad</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-3" href="#sidenav-7-3" role="button" aria-expanded="false" aria-controls="sidenav-7-3">Command-line tools</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-3"><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-1" href="#sidenav-7-3-1" role="button" aria-expanded="true" aria-controls="sidenav-7-3-1">Dart SDK</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-1"><li class="nav-item"><a class="nav-link" href="/tools/sdk">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-tool">dart</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-analyze">dart analyze</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-compile">dart compile</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-create">dart create</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-doc">dart doc</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-fix">dart fix</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-format">dart format</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-info">dart info</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/cmd">dart pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-run">dart run</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-test">dart test</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartaotruntime">dartaotruntime</a></li><li class="nav-item"><a class="nav-link" href="/tools/experiment-flags">Experiment flags</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-2" href="#sidenav-7-3-2" role="button" aria-expanded="true" aria-controls="sidenav-7-3-2">Other command-line tools</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-2"><li class="nav-item"><a class="nav-link" href="/tools/build_runner">build_runner</a></li><li class="nav-item"><a class="nav-link" href="/tools/webdev">webdev</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-4" href="#sidenav-7-4" role="button" aria-expanded="false" aria-controls="sidenav-7-4">Static analysis</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-4"><li class="nav-item"><a class="nav-link" href="/tools/analysis">Customizing static analysis</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/sound-problems">Fixing common type problems</a></li><li class="nav-item"><a class="nav-link" href="/tools/non-promotion-reasons">Fixing type promotion failures</a></li><li class="nav-item"><a class="nav-link" href="/tools/linter-rules">Linter rules</a></li><li class="nav-item"><a class="nav-link" href="/tools/diagnostic-messages">Diagnostic messages</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-5" href="#sidenav-7-5" role="button" aria-expanded="false" aria-controls="sidenav-7-5">Testing & optimization</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-5"><li class="nav-item"><a class="nav-link" href="/guides/testing">Testing</a></li><li class="nav-item"><a class="nav-link" href="/web/debugging">Debugging web apps</a></li></ul></li></ul></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-9" role="button" aria-expanded="false" aria-controls="sidenav-9">Resources</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9"><li class="nav-item"><a class="nav-link" href="/resources/dart-cheatsheet">Language cheatsheet</a></li><li class="nav-item"><a class="nav-link" href="/resources/breaking-changes">Breaking changes</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/evolution">Language evolution</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/spec">Language specification</a></li><li class="nav-item"><a class="nav-link" href="/resources/dart-3-migration">Dart 3 migration guide</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-9-6" href="#sidenav-9-6" role="button" aria-expanded="false" aria-controls="sidenav-9-6">Coming from ...</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9-6"><li class="nav-item"><a class="nav-link" href="/resources/coming-from/js-to-dart">JavaScript to Dart</a></li><li class="nav-item"><a class="nav-link" href="/resources/coming-from/swift-to-dart">Swift to Dart</a></li></ul></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/resources/faq">FAQ</a></li><li class="nav-item"><a class="nav-link" href="/resources/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/resources/books">Books</a></li><li class="nav-item"><a class="nav-link" href="/resources/videos">Videos</a></li><li class="nav-item"><a class="nav-link" href="/tutorials">Tutorials</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" href="#sidenav-10" role="button" aria-expanded="true" aria-controls="sidenav-10">Related sites</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-10"><li class="nav-item"><a class="nav-link" href="https://api.dart.dev" target="_blank" rel="noopener">API reference</a></li><li class="nav-item"><a class="nav-link" href="https://medium.com/dartlang" target="_blank" rel="noopener">Blog</a></li><li class="nav-item"><a class="nav-link" href="https://dartpad.dev" target="_blank" rel="noopener">DartPad (online editor)</a></li><li class="nav-item"><a class="nav-link" href="https://flutter.dev" target="_blank" rel="noopener">Flutter</a></li><li class="nav-item"><a class="nav-link" href="https://pub.dev" target="_blank" rel="noopener">Package site</a></li></ul></li></ul></div></div><main id="page-content"><div id="site-toc--side" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry nav-item"><a class="nav-link" href="#future">Future</a><ul class="nav"><li class="toc-entry nav-item"><a class="nav-link" href="#using-await">Using await</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#basic-usage">Basic usage</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#chaining-multiple-asynchronous-methods">Chaining multiple asynchronous methods</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#waiting-for-multiple-futures">Waiting for multiple futures</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#handling-errors-for-multiple-futures">Handling errors for multiple futures</a></li></ul></li><li class="toc-entry nav-item"><a class="nav-link" href="#stream">Stream</a><ul class="nav"><li class="toc-entry nav-item"><a class="nav-link" href="#using-an-asynchronous-for-loop">Using an asynchronous for loop</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#listening-for-stream-data">Listening for stream data</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#transforming-stream-data">Transforming stream data</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#handling-errors-and-completion">Handling errors and completion</a></li></ul></li><li class="toc-entry nav-item"><a class="nav-link" href="#more-information">More information</a></li></ul></div><article><div class="content"><nav id="subnav"><ul><li class="previous"><a href="/libraries/dart-core">⟨ dart:core</a></li><li class="next"><a href="/libraries/dart-math">dart:math ⟩</a></li></ul></nav><div id="site-content-title"><h1>dart:async</h1></div><div id="site-toc--inline" class="site-toc toc-collapsible toc-collapsed"><header class="site-toc__title">Contents <span class="site-toc--inline__toggle toc-toggle-down"><i class="material-symbols">keyboard_arrow_down</i></span> <span class="site-toc--inline__toggle toc-toggle-up"><i class="material-symbols">keyboard_arrow_up</i></span></header><ul class="section-nav"><li class="toc-entry"><a href="#future">Future</a><ul><li class="toc-entry"><a href="#using-await">Using await</a></li><li class="toc-entry"><a href="#basic-usage">Basic usage</a></li><li class="toc-entry"><a href="#chaining-multiple-asynchronous-methods">Chaining multiple asynchronous methods</a></li><li class="toc-entry"><a href="#waiting-for-multiple-futures">Waiting for multiple futures</a></li><li class="toc-entry"><a href="#handling-errors-for-multiple-futures">Handling errors for multiple futures</a></li></ul></li><li class="toc-entry"><a href="#stream">Stream</a><ul><li class="toc-entry"><a href="#using-an-asynchronous-for-loop">Using an asynchronous for loop</a></li><li class="toc-entry"><a href="#listening-for-stream-data">Listening for stream data</a></li><li class="toc-entry"><a href="#transforming-stream-data">Transforming stream data</a></li><li class="toc-entry"><a href="#handling-errors-and-completion">Handling errors and completion</a></li></ul></li><li class="toc-entry"><a href="#more-information">More information</a></li></ul><span class="site-toc--inline__toggle toc-toggle-more-items"><i class="material-symbols">more_horiz</i></span></div> <?code-excerpt replace="/ *\/\/\s+ignore_for_file:[^\n]+\n//g; /(^|\n) *\/\/\s+ignore:[^\n]+\n/$1/g; /(\n[^\n]+) *\/\/\s+ignore:[^\n]+\n/$1\n/g"?> <?code-excerpt plaster="none"?> <p>Asynchronous programming often uses callback functions, but Dart provides alternatives: <a href="https://api.dart.dev/dart-async/Future-class.html">Future</a> and <a href="https://api.dart.dev/dart-async/Stream-class.html">Stream</a> objects. A Future is like a promise for a result to be provided sometime in the future. A Stream is a way to get a sequence of values, such as events. Future, Stream, and more are in the dart:async library (<a href="https://api.dart.dev/dart-async/dart-async-library.html">API reference</a>).</p><aside class="alert alert-info"><div class="alert-header"><i class="material-symbols" aria-hidden="true">info</i> <span>Note</span></div><div class="alert-content"><p>You don't always need to use the Future or Stream APIs directly. The Dart language supports asynchronous coding using keywords such as <code>async</code> and <code>await</code>. Check out the <a href="/libraries/async/async-await">asynchronous programming tutorial</a> for details.</p></div></aside><p>The dart:async library works in both web apps and command-line apps. To use it, import dart:async:</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (import)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">import</span><span style="color:#11796D"> 'dart:async'</span><span style="color:#222222">;</span></span></code></pre></div></div><aside class="alert alert-success"><div class="alert-header"><i class="material-symbols" aria-hidden="true">lightbulb</i> <span>Tip</span></div><div class="alert-content"><p>You don't need to import dart:async to use the Future and Stream APIs, because dart:core exports those classes.</p></div></aside><div class="header-wrapper"><h2 id="future">Future</h2><a class="heading-link" href="#future" aria-label="Link to 'Future' section">#</a></div><p>Future objects appear throughout the Dart libraries, often as the object returned by an asynchronous method. When a future <em>completes</em>, its value is ready to use.</p><div class="header-wrapper"><h3 id="using-await">Using await</h3><a class="heading-link" href="#using-await" aria-label="Link to 'Using await' section">#</a></div><p>Before you directly use the Future API, consider using <code>await</code> instead. Code that uses <code>await</code> expressions can be easier to understand than code that uses the Future API.</p><p>Consider the following function. It uses Future's <code>then()</code> method to execute three asynchronous functions in a row, waiting for each one to complete before executing the next one.</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (run-using-future)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> runUsingFuture</span><span style="color:#222222">() {</span></span> <span class="line"><span style="color:#6E6E70"> // ...</span></span> <span class="line"><span style="color:#6200EE"> findEntryPoint</span><span style="color:#222222">().</span><span style="color:#6200EE">then</span><span style="color:#222222">((entryPoint) {</span></span> <span class="line"><span style="color:#D43324"> return</span><span style="color:#6200EE"> runExecutable</span><span style="color:#222222">(entryPoint, args);</span></span> <span class="line"><span style="color:#222222"> }).</span><span style="color:#6200EE">then</span><span style="color:#222222">(flushThenExit);</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>The equivalent code with await expressions looks more like synchronous code:</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (run-using-async-await)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#0468D7">Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">runUsingAsyncAwait</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#6E6E70"> // ...</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> entryPoint = </span><span style="color:#D43324">await</span><span style="color:#6200EE"> findEntryPoint</span><span style="color:#222222">();</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> exitCode = </span><span style="color:#D43324">await</span><span style="color:#6200EE"> runExecutable</span><span style="color:#222222">(entryPoint, args);</span></span> <span class="line"><span style="color:#D43324"> await</span><span style="color:#6200EE"> flushThenExit</span><span style="color:#222222">(exitCode);</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>An <code>async</code> function can catch exceptions from Futures. For example:</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (catch)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> entryPoint = </span><span style="color:#D43324">await</span><span style="color:#6200EE"> findEntryPoint</span><span style="color:#222222">();</span></span> <span class="line"><span style="color:#D43324">try</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> exitCode = </span><span style="color:#D43324">await</span><span style="color:#6200EE"> runExecutable</span><span style="color:#222222">(entryPoint, args);</span></span> <span class="line"><span style="color:#D43324"> await</span><span style="color:#6200EE"> flushThenExit</span><span style="color:#222222">(exitCode);</span></span> <span class="line"><span style="color:#222222">} </span><span style="color:#D43324">catch</span><span style="color:#222222"> (e) {</span></span> <span class="line"><span style="color:#6E6E70"> // Handle the error...</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><aside class="alert alert-warning"><div class="alert-header"><i class="material-symbols" aria-hidden="true">error</i> <span>Important</span></div><div class="alert-content"><p>Async functions return Futures. If you don't want your function to return a future, then use a different solution. For example, you might call an <code>async</code> function from your function.</p></div></aside><p>For more information on using <code>await</code> and related Dart language features, see the <a href="/libraries/async/async-await">asynchronous programming tutorial</a>.</p><div class="header-wrapper"><h3 id="basic-usage">Basic usage</h3><a class="heading-link" href="#basic-usage" aria-label="Link to 'Basic usage' section">#</a></div><p>You can use <code>then()</code> to schedule code that runs when the future completes. For example, <a href="https://pub.dev/documentation/http/latest/http/Client/read.html"><code>Client.read()</code></a> returns a Future, since HTTP requests can take a while. Using <code>then()</code> lets you run some code when that Future has completed and the promised string value is available:</p> <?code-excerpt "misc/lib/library_tour/async/basic.dart (then)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">httpClient.</span><span style="color:#6200EE">read</span><span style="color:#222222">(url).</span><span style="color:#6200EE">then</span><span style="color:#222222">((</span><span style="color:#0468D7">String</span><span style="color:#222222"> result) {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(result);</span></span> <span class="line"><span style="color:#222222">});</span></span></code></pre></div></div><p>Use <code>catchError()</code> to handle any errors or exceptions that a Future object might throw.</p> <?code-excerpt "misc/lib/library_tour/async/basic.dart (catch-error)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">httpClient.</span><span style="color:#6200EE">read</span><span style="color:#222222">(url).</span><span style="color:#6200EE">then</span><span style="color:#222222">((</span><span style="color:#0468D7">String</span><span style="color:#222222"> result) {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(result);</span></span> <span class="line"><span style="color:#222222">}).</span><span style="color:#6200EE">catchError</span><span style="color:#222222">((e) {</span></span> <span class="line"><span style="color:#6E6E70"> // Handle or ignore the error.</span></span> <span class="line"><span style="color:#222222">});</span></span></code></pre></div></div><p>The <code>then().catchError()</code> pattern is the asynchronous version of <code>try</code>-<code>catch</code>.</p><aside class="alert alert-warning"><div class="alert-header"><i class="material-symbols" aria-hidden="true">error</i> <span>Important</span></div><div class="alert-content"><p>Be sure to invoke <code>catchError()</code> on the result of <code>then()</code>鈥攏ot on the result of the original <code>Future</code>. Otherwise, the <code>catchError()</code> can handle errors only from the original Future's computation, but not from the handler registered by <code>then()</code>.</p></div></aside><div class="header-wrapper"><h3 id="chaining-multiple-asynchronous-methods">Chaining multiple asynchronous methods</h3><a class="heading-link" href="#chaining-multiple-asynchronous-methods" aria-label="Link to 'Chaining multiple asynchronous methods' section">#</a></div><p>The <code>then()</code> method returns a Future, providing a useful way to run multiple asynchronous functions in a certain order. If the callback registered with <code>then()</code> returns a Future, <code>then()</code> returns a Future that will complete with the same result as the Future returned from the callback. If the callback returns a value of any other type, <code>then()</code> creates a new Future that completes with the value.</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (then-chain)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#0468D7">Future</span><span style="color:#222222"> result = </span><span style="color:#6200EE">costlyQuery</span><span style="color:#222222">(url);</span></span> <span class="line"><span style="color:#222222">result</span></span> <span class="line"><span style="color:#222222"> .</span><span style="color:#6200EE">then</span><span style="color:#222222">((value) => </span><span style="color:#6200EE">expensiveWork</span><span style="color:#222222">(value))</span></span> <span class="line"><span style="color:#222222"> .</span><span style="color:#6200EE">then</span><span style="color:#222222">((_) => </span><span style="color:#6200EE">lengthyComputation</span><span style="color:#222222">())</span></span> <span class="line"><span style="color:#222222"> .</span><span style="color:#6200EE">then</span><span style="color:#222222">((_) => </span><span style="color:#6200EE">print</span><span style="color:#222222">(</span><span style="color:#11796D">'Done!'</span><span style="color:#222222">))</span></span> <span class="line"><span style="color:#222222"> .</span><span style="color:#6200EE">catchError</span><span style="color:#222222">((exception) {</span></span> <span class="line"><span style="color:#6E6E70"> /* Handle exception... */</span></span> <span class="line"><span style="color:#222222">});</span></span></code></pre></div></div><p>In the preceding example, the methods run in the following order:</p><ol><li><code>costlyQuery()</code></li><li><code>expensiveWork()</code></li><li><code>lengthyComputation()</code></li></ol><p>Here is the same code written using await:</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (then-chain-as-await)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">try</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#D43324"> final</span><span style="color:#222222"> value = </span><span style="color:#D43324">await</span><span style="color:#6200EE"> costlyQuery</span><span style="color:#222222">(url);</span></span> <span class="line"><span style="color:#D43324"> await</span><span style="color:#6200EE"> expensiveWork</span><span style="color:#222222">(value);</span></span> <span class="line"><span style="color:#D43324"> await</span><span style="color:#6200EE"> lengthyComputation</span><span style="color:#222222">();</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'Done!'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#222222">} </span><span style="color:#D43324">catch</span><span style="color:#222222"> (e) {</span></span> <span class="line"><span style="color:#6E6E70"> /* Handle exception... */</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><div class="header-wrapper"><h3 id="waiting-for-multiple-futures">Waiting for multiple futures</h3><a class="heading-link" href="#waiting-for-multiple-futures" aria-label="Link to 'Waiting for multiple futures' section">#</a></div><p>Sometimes your algorithm needs to invoke many asynchronous functions and wait for them all to complete before continuing. Use the <a href="https://api.dart.dev/dart-async/Future/wait.html">Future.wait()</a> static method to manage multiple Futures and wait for them to complete:</p> <?code-excerpt "misc/lib/library_tour/async/future.dart (wait)" replace="/elideBody;/\/* ... *\//g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#0468D7">Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">deleteLotsOfFiles</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#0468D7">Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">copyLotsOfFiles</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#0468D7">Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">checksumLotsOfOtherFiles</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">await</span><span style="color:#0468D7"> Future</span><span style="color:#222222">.</span><span style="color:#6200EE">wait</span><span style="color:#222222">([</span></span> <span class="line"><span style="color:#6200EE"> deleteLotsOfFiles</span><span style="color:#222222">(),</span></span> <span class="line"><span style="color:#6200EE"> copyLotsOfFiles</span><span style="color:#222222">(),</span></span> <span class="line"><span style="color:#6200EE"> checksumLotsOfOtherFiles</span><span style="color:#222222">(),</span></span> <span class="line"><span style="color:#222222">]);</span></span> <span class="line"><span style="color:#6200EE">print</span><span style="color:#222222">(</span><span style="color:#11796D">'Done with all the long steps!'</span><span style="color:#222222">);</span></span></code></pre></div></div><p><code>Future.wait()</code> returns a future which completes once all the provided futures have completed. It completes either with their results, or with an error if any of the provided futures fail.</p><div class="header-wrapper"><h3 id="handling-errors-for-multiple-futures">Handling errors for multiple futures</h3><a class="heading-link" href="#handling-errors-for-multiple-futures" aria-label="Link to 'Handling errors for multiple futures' section">#</a></div><p>You can also wait for parallel operations on an <a href="https://api.dart.dev/dart-async/FutureIterable/wait.html">iterable</a> or <a href="https://api.dart.dev/dart-async/FutureRecord2/wait.html">record</a> of futures.</p><p>These extensions return a future with the resulting values of all provided futures. Unlike <code>Future.wait</code>, they also let you handle errors.</p><p>If any future in the collection completes with an error, <code>wait</code> completes with a <a href="https://api.dart.dev/dart-async/ParallelWaitError-class.html"><code>ParallelWaitError</code></a>. This allows the caller to handle individual errors and dispose successful results if necessary.</p><p>When you <em>don't</em> need the result values from each individual future, use <code>wait</code> on an <em>iterable</em> of futures:</p><div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> main</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#0468D7"> Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">delete</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#0468D7"> Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">copy</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#0468D7"> Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">errorResult</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#222222"> </span></span> <span class="line"><span style="color:#D43324"> try</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#6E6E70"> // Wait for each future in a list, returns a list of futures:</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> results = </span><span style="color:#D43324">await</span><span style="color:#222222"> [</span><span style="color:#6200EE">delete</span><span style="color:#222222">(), </span><span style="color:#6200EE">copy</span><span style="color:#222222">(), </span><span style="color:#6200EE">errorResult</span><span style="color:#222222">()].wait;</span></span> <span class="line"></span> <span class="line"><span style="color:#222222"> } </span><span style="color:#D43324">on</span><span style="color:#0468D7"> ParallelWaitError</span><span style="color:#222222"><</span><span style="color:#0468D7">List</span><span style="color:#222222"><</span><span style="color:#0468D7">bool</span><span style="color:#222222">?>, </span><span style="color:#0468D7">List</span><span style="color:#222222"><</span><span style="color:#0468D7">AsyncError</span><span style="color:#222222">?>> </span><span style="color:#D43324">catch</span><span style="color:#222222"> (e) {</span></span> <span class="line"></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e.values[</span><span style="color:#11796D">0</span><span style="color:#222222">]); </span><span style="color:#6E6E70">// Prints successful future</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e.values[</span><span style="color:#11796D">1</span><span style="color:#222222">]); </span><span style="color:#6E6E70">// Prints successful future</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e.values[</span><span style="color:#11796D">2</span><span style="color:#222222">]); </span><span style="color:#6E6E70">// Prints null when the result is an error</span></span> <span class="line"></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e.errors[</span><span style="color:#11796D">0</span><span style="color:#222222">]); </span><span style="color:#6E6E70">// Prints null when the result is successful</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e.errors[</span><span style="color:#11796D">1</span><span style="color:#222222">]); </span><span style="color:#6E6E70">// Prints null when the result is successful</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e.errors[</span><span style="color:#11796D">2</span><span style="color:#222222">]); </span><span style="color:#6E6E70">// Prints error</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>When you <em>do</em> need the individual result values from each future, use <code>wait</code> on a <em>record</em> of futures. This provides the additional benefit that the futures can be of different types:</p><div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> main</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#0468D7"> Future</span><span style="color:#222222"><</span><span style="color:#0468D7">int</span><span style="color:#222222">> </span><span style="color:#6200EE">delete</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#0468D7"> Future</span><span style="color:#222222"><</span><span style="color:#0468D7">String</span><span style="color:#222222">> </span><span style="color:#6200EE">copy</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"><span style="color:#0468D7"> Future</span><span style="color:#222222"><</span><span style="color:#0468D7">bool</span><span style="color:#222222">> </span><span style="color:#6200EE">errorResult</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> => ...</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324"> try</span><span style="color:#222222"> { </span></span> <span class="line"><span style="color:#6E6E70"> // Wait for each future in a record, returns a record of futures:</span></span> <span class="line"><span style="color:#222222"> (</span><span style="color:#0468D7">int</span><span style="color:#222222">, </span><span style="color:#0468D7">String</span><span style="color:#222222">, </span><span style="color:#0468D7">bool</span><span style="color:#222222">) result = </span><span style="color:#D43324">await</span><span style="color:#222222"> (</span><span style="color:#6200EE">delete</span><span style="color:#222222">(), </span><span style="color:#6200EE">copy</span><span style="color:#222222">(), </span><span style="color:#6200EE">errorResult</span><span style="color:#222222">()).wait;</span></span> <span class="line"><span style="color:#222222"> </span></span> <span class="line"><span style="color:#222222"> } </span><span style="color:#D43324">on</span><span style="color:#0468D7"> ParallelWaitError</span><span style="color:#222222"><(</span><span style="color:#0468D7">int</span><span style="color:#222222">?, </span><span style="color:#0468D7">String</span><span style="color:#222222">?, </span><span style="color:#0468D7">bool</span><span style="color:#222222">?),</span></span> <span class="line"><span style="color:#222222"> (</span><span style="color:#0468D7">AsyncError</span><span style="color:#222222">?, </span><span style="color:#0468D7">AsyncError</span><span style="color:#222222">?, </span><span style="color:#0468D7">AsyncError</span><span style="color:#222222">?)> </span><span style="color:#D43324">catch</span><span style="color:#222222"> (e) {</span></span> <span class="line"><span style="color:#6E6E70"> // ...</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"></span> <span class="line"><span style="color:#6E6E70"> // Do something with the results:</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> deleteInt = result.$1;</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> copyString = result.$2;</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> errorBool = result.$3;</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><div class="header-wrapper"><h2 id="stream">Stream</h2><a class="heading-link" href="#stream" aria-label="Link to 'Stream' section">#</a></div><p>Stream objects appear throughout Dart APIs, representing sequences of data. For example, HTML events such as button clicks are delivered using streams. You can also read a file as a stream.</p><div class="header-wrapper"><h3 id="using-an-asynchronous-for-loop">Using an asynchronous for loop</h3><a class="heading-link" href="#using-an-asynchronous-for-loop" aria-label="Link to 'Using an asynchronous for loop' section">#</a></div><p>Sometimes you can use an asynchronous for loop (<code>await for</code>) instead of using the Stream API.</p><p>Consider the following function. It uses Stream's <code>listen()</code> method to subscribe to a list of files, passing in a function literal that searches each file or directory.</p> <?code-excerpt "misc/lib/library_tour/async/stream.dart (listen)" replace="/listen/[!$&!]/g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> main</span><span style="color:#222222">(</span><span style="color:#0468D7">List</span><span style="color:#222222"><</span><span style="color:#0468D7">String</span><span style="color:#222222">> arguments) {</span></span> <span class="line"><span style="color:#6E6E70"> // ...</span></span> <span class="line"><span style="color:#0468D7"> FileSystemEntity</span><span style="color:#222222">.</span><span style="color:#6200EE">isDirectory</span><span style="color:#222222">(searchPath).</span><span style="color:#6200EE">then</span><span style="color:#222222">((isDir) {</span></span> <span class="line"><span style="color:#D43324"> if</span><span style="color:#222222"> (isDir) {</span></span> <span class="line"><span style="color:#D43324"> final</span><span style="color:#222222"> startingDir = </span><span style="color:#0468D7">Directory</span><span style="color:#222222">(searchPath);</span></span> <span class="line"><span style="color:#222222"> startingDir.</span><span style="color:#6200EE">list</span><span style="color:#222222">().</span><mark class="highlight"><span style="color:#6200EE">listen</span></mark><span style="color:#222222">((entity) {</span></span> <span class="line"><span style="color:#D43324"> if</span><span style="color:#222222"> (entity is </span><span style="color:#0468D7">File</span><span style="color:#222222">) {</span></span> <span class="line"><span style="color:#6200EE"> searchFile</span><span style="color:#222222">(entity, searchTerms);</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#222222"> });</span></span> <span class="line"><span style="color:#222222"> } </span><span style="color:#D43324">else</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#6200EE"> searchFile</span><span style="color:#222222">(</span><span style="color:#0468D7">File</span><span style="color:#222222">(searchPath), searchTerms);</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#222222"> });</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>The equivalent code with await expressions, including an asynchronous for loop (<code>await for</code>), looks more like synchronous code:</p> <?code-excerpt "misc/lib/library_tour/async/stream.dart (await-for)" replace="/await for/[!$&!]/g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> main</span><span style="color:#222222">(</span><span style="color:#0468D7">List</span><span style="color:#222222"><</span><span style="color:#0468D7">String</span><span style="color:#222222">> arguments) </span><span style="color:#D43324">async</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#6E6E70"> // ...</span></span> <span class="line"><span style="color:#D43324"> if</span><span style="color:#222222"> (</span><span style="color:#D43324">await</span><span style="color:#0468D7"> FileSystemEntity</span><span style="color:#222222">.</span><span style="color:#6200EE">isDirectory</span><span style="color:#222222">(searchPath)) {</span></span> <span class="line"><span style="color:#D43324"> final</span><span style="color:#222222"> startingDir = </span><span style="color:#0468D7">Directory</span><span style="color:#222222">(searchPath);</span></span> <span class="line"><span style="color:#D43324"> </span><mark class="highlight"><span style="color:#D43324">await</span><span style="color:#D43324"> for</span></mark><span style="color:#222222"> (</span><span style="color:#D43324">final</span><span style="color:#222222"> entity </span><span style="color:#D43324">in</span><span style="color:#222222"> startingDir.</span><span style="color:#6200EE">list</span><span style="color:#222222">()) {</span></span> <span class="line"><span style="color:#D43324"> if</span><span style="color:#222222"> (entity is </span><span style="color:#0468D7">File</span><span style="color:#222222">) {</span></span> <span class="line"><span style="color:#6200EE"> searchFile</span><span style="color:#222222">(entity, searchTerms);</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#222222"> } </span><span style="color:#D43324">else</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#6200EE"> searchFile</span><span style="color:#222222">(</span><span style="color:#0468D7">File</span><span style="color:#222222">(searchPath), searchTerms);</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><aside class="alert alert-warning"><div class="alert-header"><i class="material-symbols" aria-hidden="true">error</i> <span>Important</span></div><div class="alert-content"><p>Before using <code>await for</code>, make sure that it makes the code clearer and that you really do want to wait for all of the stream's results. For example, you usually should <strong>not</strong> use <code>await for</code> for DOM event listeners, because the DOM sends endless streams of events. If you use <code>await for</code> to register two DOM event listeners in a row, then the second kind of event is never handled.</p></div></aside><p>For more information on using <code>await</code> and related Dart language features, see the <a href="/libraries/async/async-await">asynchronous programming tutorial</a>.</p><div class="header-wrapper"><h3 id="listening-for-stream-data">Listening for stream data</h3><a class="heading-link" href="#listening-for-stream-data" aria-label="Link to 'Listening for stream data' section">#</a></div><p>To get each value as it arrives, either use <code>await for</code> or subscribe to the stream using the <code>listen()</code> method:</p> <?code-excerpt "misc/lib/library_tour/async/stream_web.dart (listen)" replace="/listen/[!$&!]/g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#6E6E70">// Add an event handler to a button.</span></span> <span class="line"><span style="color:#222222">submitButton.onClick.</span><mark class="highlight"><span style="color:#6200EE">listen</span></mark><span style="color:#222222">((e) {</span></span> <span class="line"><span style="color:#6E6E70"> // When the button is clicked, it runs this code.</span></span> <span class="line"><span style="color:#6200EE"> submitData</span><span style="color:#222222">();</span></span> <span class="line"><span style="color:#222222">});</span></span></code></pre></div></div><p>In this example, the <code>onClick</code> property is a <code>Stream</code> object provided by the submit button.</p><p>If you care about only one event, you can get it using a property such as <code>first</code>, <code>last</code>, or <code>single</code>. To test the event before handling it, use a method such as <code>firstWhere()</code>, <code>lastWhere()</code>, or <code>singleWhere()</code>.</p><p>If you care about a subset of events, you can use methods such as <code>skip()</code>, <code>skipWhile()</code>, <code>take()</code>, <code>takeWhile()</code>, and <code>where()</code>.</p><div class="header-wrapper"><h3 id="transforming-stream-data">Transforming stream data</h3><a class="heading-link" href="#transforming-stream-data" aria-label="Link to 'Transforming stream data' section">#</a></div><p>Often, you need to change the format of a stream's data before you can use it. Use the <code>transform()</code> method to produce a stream with a different type of data:</p> <?code-excerpt "misc/lib/library_tour/async/stream.dart (transform)"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> lines =</span></span> <span class="line"><span style="color:#222222"> inputStream.</span><span style="color:#6200EE">transform</span><span style="color:#222222">(utf8.decoder).</span><span style="color:#6200EE">transform</span><span style="color:#222222">(</span><span style="color:#D43324">const</span><span style="color:#0468D7"> LineSplitter</span><span style="color:#222222">());</span></span></code></pre></div></div><p>This example uses two transformers. First it uses utf8.decoder to transform the stream of integers into a stream of strings. Then it uses a LineSplitter to transform the stream of strings into a stream of separate lines. These transformers are from the dart:convert library (see the <a href="/libraries/dart-convert">dart:convert section</a>).</p><div class="header-wrapper"><h3 id="handling-errors-and-completion">Handling errors and completion</h3><a class="heading-link" href="#handling-errors-and-completion" aria-label="Link to 'Handling errors and completion' section">#</a></div><p>How you specify error and completion handling code depends on whether you use an asynchronous for loop (<code>await for</code>) or the Stream API.</p><p>If you use an asynchronous for loop, then use try-catch to handle errors. Code that executes after the stream is closed goes after the asynchronous for loop.</p> <?code-excerpt "misc/lib/library_tour/async/stream.dart (read-file-await-for)" replace="/try|catch/[!$&!]/g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#0468D7">Future</span><span style="color:#222222"><</span><span style="color:#D43324">void</span><span style="color:#222222">> </span><span style="color:#6200EE">readFileAwaitFor</span><span style="color:#222222">() </span><span style="color:#D43324">async</span><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> config = </span><span style="color:#0468D7">File</span><span style="color:#222222">(</span><span style="color:#11796D">'config.txt'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#0468D7"> Stream</span><span style="color:#222222"><</span><span style="color:#0468D7">List</span><span style="color:#222222"><</span><span style="color:#0468D7">int</span><span style="color:#222222">>> inputStream = config.</span><span style="color:#6200EE">openRead</span><span style="color:#222222">();</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324"> var</span><span style="color:#222222"> lines =</span></span> <span class="line"><span style="color:#222222"> inputStream.</span><span style="color:#6200EE">transform</span><span style="color:#222222">(utf8.decoder).</span><span style="color:#6200EE">transform</span><span style="color:#222222">(</span><span style="color:#D43324">const</span><span style="color:#0468D7"> LineSplitter</span><span style="color:#222222">());</span></span> <span class="line"><span style="color:#D43324"> </span><mark class="highlight"><span style="color:#D43324">try</span></mark><span style="color:#222222"> {</span></span> <span class="line"><span style="color:#D43324"> await</span><span style="color:#D43324"> for</span><span style="color:#222222"> (</span><span style="color:#D43324">final</span><span style="color:#222222"> line </span><span style="color:#D43324">in</span><span style="color:#222222"> lines) {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'Got </span><span style="color:#11796D">${</span><span style="color:#222222">line</span><span style="color:#11796D">.</span><span style="color:#222222">length</span><span style="color:#11796D">}</span><span style="color:#11796D"> characters from stream'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'file is now closed'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#222222"> } </span><mark class="highlight"><span style="color:#D43324">catch</span></mark><span style="color:#222222"> (e) {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e);</span></span> <span class="line"><span style="color:#222222"> }</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>If you use the Stream API, then handle errors by registering an <code>onError</code> listener. Run code after the stream is closed by registering an <code>onDone</code> listener.</p> <?code-excerpt "misc/lib/library_tour/async/stream.dart (on-done)" replace="/onDone|onError/[!$&!]/g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">var</span><span style="color:#222222"> config = </span><span style="color:#0468D7">File</span><span style="color:#222222">(</span><span style="color:#11796D">'config.txt'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#0468D7">Stream</span><span style="color:#222222"><</span><span style="color:#0468D7">List</span><span style="color:#222222"><</span><span style="color:#0468D7">int</span><span style="color:#222222">>> inputStream = config.</span><span style="color:#6200EE">openRead</span><span style="color:#222222">();</span></span> <span class="line"></span> <span class="line"><span style="color:#222222">inputStream.</span><span style="color:#6200EE">transform</span><span style="color:#222222">(utf8.decoder).</span><span style="color:#6200EE">transform</span><span style="color:#222222">(</span><span style="color:#D43324">const</span><span style="color:#0468D7"> LineSplitter</span><span style="color:#222222">()).</span><span style="color:#6200EE">listen</span><span style="color:#222222">(</span></span> <span class="line"><span style="color:#222222"> (</span><span style="color:#0468D7">String</span><span style="color:#222222"> line) {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'Got </span><span style="color:#11796D">${</span><span style="color:#222222">line</span><span style="color:#11796D">.</span><span style="color:#222222">length</span><span style="color:#11796D">}</span><span style="color:#11796D"> characters from stream'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#222222">}, </span><mark class="highlight"><span style="color:#222222">onDone</span></mark><span style="color:#222222">: () {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(</span><span style="color:#11796D">'file is now closed'</span><span style="color:#222222">);</span></span> <span class="line"><span style="color:#222222">}, </span><mark class="highlight"><span style="color:#222222">onError</span></mark><span style="color:#222222">: (e) {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(e);</span></span> <span class="line"><span style="color:#222222">});</span></span></code></pre></div></div><div class="header-wrapper"><h2 id="more-information">More information</h2><a class="heading-link" href="#more-information" aria-label="Link to 'More information' section">#</a></div><p>For some examples of using Future and Stream in command-line apps, check out the <a href="/libraries/dart-io">dart:io documentation</a>. Also see these articles and tutorials:</p><ul><li><a href="/libraries/async/async-await">Asynchronous programming: futures, async, await</a></li><li><a href="/libraries/async/futures-error-handling">Futures and error handling</a></li><li><a href="/libraries/async/using-streams">Asynchronous programming: streams</a></li><li><a href="/libraries/async/creating-streams">Creating streams in Dart</a></li><li><a href="/language/concurrency">Dart asynchronous programming: Isolates and event loops</a></li></ul><nav id="subnav"><ul><li class="previous"><a href="/libraries/dart-core">⟨ dart:core</a></li><li class="next"><a href="/libraries/dart-math">dart:math ⟩</a></li></ul></nav><p id="page-github-links"><span>Unless stated otherwise, the documentation on this site reflects Dart 3.5.4. Page last updated on 2024-11-17.</span> <a href="https://github.com/dart-lang/site-www/tree/main/src/content/libraries/dart-async.md" target="_blank" rel="noopener">View source</a> <span>or </span><a href="https://github.com/dart-lang/site-www/issues/new?template=1_page_issue.yml&page-url=https://dart.dev/libraries/dart-async/&page-source=https://github.com/dart-lang/site-www/tree/main/src/content/libraries/dart-async.md" title="Report an issue with this page" target="_blank" rel="noopener">report an issue</a>.</p></div></article></main><footer id="page-footer"><div class="footer-section footer-main"><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart" width="164"></a><div class="footer-social-links"><a href="https://medium.com/dartlang" target="_blank" rel="noopener" title="Medium blog"><svg><use href="/assets/img/social/medium.svg#medium"></use></svg> </a><a href="https://github.com/dart-lang" target="_blank" rel="noopener" title="GitHub"><svg><use href="/assets/img/social/github.svg#github"></use></svg> </a><a href="https://twitter.com/dart_lang" target="_blank" rel="noopener" title="X (Twitter)"><svg><use href="/assets/img/social/x.svg#x"></use></svg></a></div></div><div class="footer-section footer-tray"><div class="footer-licenses">Except as otherwise noted, this site is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>, and code samples are licensed under the <a href="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</a>.</div><div class="footer-utility-links"><ul><li><a href="/terms" title="Terms of use">Terms</a></li><li><a href="https://policies.google.com/privacy" target="_blank" rel="noopener" title="Privacy policy">Privacy</a></li><li><a href="/security" title="Security philosophy and practices">Security</a></li></ul></div></div></footer></body></html>