// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'dart:async'; Future foo() async => 42; Future simpleAsyncAwait(Future a, Future b) async { return (await a) + (await b); } Future loops(List list) async { int sum = 0; for (int i = 0; i < 10; ++i) { for (var j in list) { sum += i + j + await foo(); } } for (int k = 0; k < 10; ++k) { sum += k; } return sum; } Future tryCatchRethrow(Future a, Future b, Future c) async { int x = 1; try { x = x + await a; } catch (e) { if (e is Error) { return 42; } x = x + await b; rethrow; } finally { print('fin'); x = x + await c; return x; } } closure(Future a) { int x = 3; Future nested() async { int y = 4; try { x = 5; y = await a; return x + y; } finally { print('fin'); } } return nested; } Future testAssert(Future a) async { assert((await a) == 42); return 7; } var asyncInFieldInitializer = (Future x) async { await x; }; main() {}