OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library future_delayed_test; | |
6 | |
7 import 'package:async_helper/async_helper.dart'; | |
8 import "package:expect/expect.dart"; | |
9 import 'dart:async'; | |
10 | |
11 Future<int> createIntFuture() { | |
12 return new Future<int>.value(499); | |
13 } | |
14 | |
15 unnamed() { | |
16 asyncStart(); | |
17 new Future<int>(createIntFuture).then((x) { | |
18 Expect.equals(499, x); | |
19 asyncEnd(); | |
20 }); | |
21 } | |
22 | |
23 delayed() { | |
24 asyncStart(); | |
25 new Future<int>.delayed(const Duration(milliseconds: 2), createIntFuture) | |
26 .then((x) { | |
27 Expect.equals(499, x); | |
28 asyncEnd(); | |
29 }); | |
30 } | |
31 | |
32 microtask() { | |
33 asyncStart(); | |
34 new Future<int>.microtask(createIntFuture).then((x) { | |
35 Expect.equals(499, x); | |
36 asyncEnd(); | |
37 }); | |
38 } | |
39 | |
40 sync() { | |
41 asyncStart(); | |
42 new Future<int>.sync(createIntFuture).then((x) { | |
43 Expect.equals(499, x); | |
44 asyncEnd(); | |
45 }); | |
46 } | |
47 | |
48 main() { | |
49 asyncStart(); | |
50 // Test that all the Future constructors take functions that return a Future | |
51 // as argument. | |
52 // In particular the constructors must not type their argument as | |
53 // `T computation()`. | |
54 unnamed(); | |
55 delayed(); | |
56 microtask(); | |
57 sync(); | |
58 asyncEnd(); | |
59 } | |
OLD | NEW |