Fix strong mode warnings.
R=jmesserly@google.com
Review URL: https://codereview.chromium.org//1843303002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc852aa..9ad86d0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.2.2
+
+* Fix strong mode warnings and add generic method annotations.
+
## 1.2.1
* Internal changes only.
diff --git a/lib/pool.dart b/lib/pool.dart
index 3279160..f7bfd82 100644
--- a/lib/pool.dart
+++ b/lib/pool.dart
@@ -106,16 +106,18 @@
/// Future.
///
/// The return value of [callback] is piped to the returned Future.
- Future withResource(callback()) {
+ Future/*<T>*/ withResource/*<T>*/(/*=T*/ callback()) async {
if (isClosed) {
throw new StateError(
"withResource() may not be called on a closed Pool.");
}
- // TODO(nweiz): Use async/await when sdk#23497 is fixed.
- return request().then((resource) {
- return new Future.sync(callback).whenComplete(resource.release);
- });
+ var resource = await request();
+ try {
+ return await callback();
+ } finally {
+ resource.release();
+ }
}
/// Closes the pool so that no more resources are requested.
@@ -189,7 +191,7 @@
_onReleaseCompleters.removeFirst().completeError(error, stackTrace);
});
- var completer = new Completer.sync();
+ var completer = new Completer<PoolResource>.sync();
_onReleaseCompleters.add(completer);
return completer.future;
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 9635620..314ac04 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: pool
-version: 1.2.1
+version: 1.2.2
author: Dart Team <misc@dartlang.org>
description: A class for managing a finite pool of resources.
homepage: https://github.com/dart-lang/pool
diff --git a/test/pool_test.dart b/test/pool_test.dart
index 65fd00e..91e6833 100644
--- a/test/pool_test.dart
+++ b/test/pool_test.dart
@@ -276,7 +276,7 @@
test("disallows request() and withResource()", () {
var pool = new Pool(1)..close();
expect(pool.request, throwsStateError);
- expect(() => pool.withResource(() {}), throwsStateError);
+ expect(pool.withResource(() {}), throwsStateError);
});
test("pending requests are fulfilled", () async {