Chromium Code Reviews| 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> voidToIntFuture() { | |
|
Lasse Reichstein Nielsen
2015/08/14 22:05:04
drop the "void" - just "intFunction". void is only
floitsch
2015/08/17 09:34:30
renamed to 'createIntFuture'.
| |
| 12 return new Future<int>.value(499); | |
| 13 } | |
| 14 | |
| 15 unnamed() { | |
| 16 asyncStart(); | |
| 17 new Future<int>(voidToIntFuture) | |
| 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), voidToIntFuture) | |
| 27 .then((x) { | |
| 28 Expect.equals(499, x); | |
| 29 asyncEnd(); | |
| 30 }); | |
| 31 } | |
| 32 | |
| 33 microtask() { | |
| 34 asyncStart(); | |
| 35 new Future<int>.microtask(voidToIntFuture) | |
| 36 .then((x) { | |
| 37 Expect.equals(499, x); | |
| 38 asyncEnd(); | |
| 39 }); | |
| 40 } | |
| 41 | |
| 42 sync() { | |
| 43 asyncStart(); | |
| 44 new Future<int>.sync(voidToIntFuture) | |
| 45 .then((x) { | |
| 46 Expect.equals(499, x); | |
| 47 asyncEnd(); | |
| 48 }); | |
| 49 } | |
| 50 | |
| 51 main() { | |
|
Lasse Reichstein Nielsen
2015/08/14 22:05:04
I'd prefer if main stared with asyncStart() and en
floitsch
2015/08/17 09:34:30
Done.
| |
| 52 // Test that all the Future constructors take functions that return a Future | |
| 53 // as argument. | |
| 54 // In particular the constructors must not type their argument as | |
| 55 // `T computation()`. | |
| 56 unnamed(); | |
| 57 delayed(); | |
| 58 microtask(); | |
| 59 sync(); | |
| 60 } | |
| OLD | NEW |