Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Unified Diff: lib/pool.dart

Issue 1843303002: Fix strong mode warnings. (Closed) Base URL: git@github.com:dart-lang/pool@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/pool.dart
diff --git a/lib/pool.dart b/lib/pool.dart
index 3279160be58a5785f4787a6d1a26d274c4d943ec..f7bfd828b8891c1d6b5dd99dc403072583e2aeb1 100644
--- a/lib/pool.dart
+++ b/lib/pool.dart
@@ -106,16 +106,18 @@ class Pool {
/// 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 @@ class Pool {
_onReleaseCompleters.removeFirst().completeError(error, stackTrace);
});
- var completer = new Completer.sync();
+ var completer = new Completer<PoolResource>.sync();
_onReleaseCompleters.add(completer);
return completer.future;
}
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698