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) |
| 18 .then((x) { |
| 19 Expect.equals(499, x); |
| 20 asyncEnd(); |
| 21 }); |
| 22 } |
| 23 |
| 24 delayed() { |
| 25 asyncStart(); |
| 26 new Future<int>.delayed(const Duration(milliseconds: 2), createIntFuture) |
| 27 .then((x) { |
| 28 Expect.equals(499, x); |
| 29 asyncEnd(); |
| 30 }); |
| 31 } |
| 32 |
| 33 microtask() { |
| 34 asyncStart(); |
| 35 new Future<int>.microtask(createIntFuture) |
| 36 .then((x) { |
| 37 Expect.equals(499, x); |
| 38 asyncEnd(); |
| 39 }); |
| 40 } |
| 41 |
| 42 sync() { |
| 43 asyncStart(); |
| 44 new Future<int>.sync(createIntFuture) |
| 45 .then((x) { |
| 46 Expect.equals(499, x); |
| 47 asyncEnd(); |
| 48 }); |
| 49 } |
| 50 |
| 51 main() { |
| 52 asyncStart(); |
| 53 // Test that all the Future constructors take functions that return a Future |
| 54 // as argument. |
| 55 // In particular the constructors must not type their argument as |
| 56 // `T computation()`. |
| 57 unnamed(); |
| 58 delayed(); |
| 59 microtask(); |
| 60 sync(); |
| 61 asyncEnd(); |
| 62 } |
OLD | NEW |