• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
7import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
8
9void main() {
10  test('Message loop flushes microtasks between iterations', () async {
11    final List<int> tasks = <int>[];
12
13    tasks.add(1);
14
15    // Flush 0 microtasks.
16    await Future<void>.delayed(Duration.zero);
17
18    scheduleMicrotask(() {
19      tasks.add(3);
20    });
21    scheduleMicrotask(() {
22      tasks.add(4);
23    });
24
25    tasks.add(2);
26
27    // Flush 2 microtasks.
28    await Future<void>.delayed(Duration.zero);
29
30    scheduleMicrotask(() {
31      tasks.add(6);
32    });
33    scheduleMicrotask(() {
34      tasks.add(7);
35    });
36    scheduleMicrotask(() {
37      tasks.add(8);
38    });
39
40    tasks.add(5);
41
42    // Flush 3 microtasks.
43    await Future<void>.delayed(Duration.zero);
44
45    tasks.add(9);
46
47    expect(tasks, <int>[1, 2, 3, 4, 5, 6, 7, 8, 9]);
48  });
49}
50