| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | |
| 6 | |
| 7 import 'package:async/async.dart'; | 5 import 'package:async/async.dart'; |
| 8 import 'package:test/test.dart'; | 6 import 'package:test/test.dart'; |
| 9 | 7 |
| 10 main() { | 8 main() { |
| 11 var cache; | 9 var cache; |
| 12 setUp(() => cache = new AsyncMemoizer()); | 10 setUp(() => cache = new AsyncMemoizer()); |
| 13 | 11 |
| 14 test("runs the function only the first time runOnce() is called", () async { | 12 test("runs the function only the first time runOnce() is called", () async { |
| 15 var count = 0; | 13 var count = 0; |
| 16 expect(await cache.runOnce(() => count++), equals(0)); | 14 expect(await cache.runOnce(() => count++), equals(0)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 expect(cache.runOnce(() async => "value"), completion(equals("value"))); | 29 expect(cache.runOnce(() async => "value"), completion(equals("value"))); |
| 32 expect(cache.runOnce(() {}), completion(equals("value"))); | 30 expect(cache.runOnce(() {}), completion(equals("value"))); |
| 33 }); | 31 }); |
| 34 | 32 |
| 35 test("forwards the error from an async function", () async { | 33 test("forwards the error from an async function", () async { |
| 36 expect(cache.future, throwsA("error")); | 34 expect(cache.future, throwsA("error")); |
| 37 expect(cache.runOnce(() async => throw "error"), throwsA("error")); | 35 expect(cache.runOnce(() async => throw "error"), throwsA("error")); |
| 38 expect(cache.runOnce(() {}), throwsA("error")); | 36 expect(cache.runOnce(() {}), throwsA("error")); |
| 39 }); | 37 }); |
| 40 } | 38 } |
| OLD | NEW |