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 import 'dart:async'; | |
| 6 | |
| 7 import 'package:async/async.dart'; | |
| 8 import 'package:test/test.dart'; | |
| 9 | |
| 10 main() { | |
| 11 var cache; | |
| 12 setUp(() => cache = new AsyncMemoizer()); | |
| 13 | |
| 14 test("runs the function only the first time runOnce() is called", () async { | |
| 15 var count = 0; | |
| 16 await cache.runOnce(() => count++); | |
| 17 expect(count, equals(1)); | |
|
Lasse Reichstein Nielsen
2015/07/08 07:37:34
Remember the result too, and check that it contain
nweiz
2015/07/09 00:45:13
Done.
| |
| 18 | |
| 19 await cache.runOnce(() => count++); | |
| 20 expect(count, equals(1)); | |
| 21 }); | |
| 22 | |
| 23 test("forwards the return value from the function", () async { | |
| 24 expect(cache.runOnce(() => "value"), completion(equals("value"))); | |
| 25 expect(cache.runOnce(() {}), completion(equals("value"))); | |
| 26 }); | |
| 27 | |
| 28 test("forwards the error from the function", () async { | |
| 29 expect(cache.runOnce(() => throw "error"), throwsA("error")); | |
| 30 expect(cache.runOnce(() {}), throwsA("error")); | |
| 31 }); | |
|
Lasse Reichstein Nielsen
2015/07/08 07:37:34
Try with a function returning a Future too, prefer
nweiz
2015/07/09 00:45:13
Done.
| |
| 32 } | |
| OLD | NEW |