Skip to content

Commit

Permalink
Pool.withResource() should take () -> FutureOr<T>. (dart-lang/pool#7)
Browse files Browse the repository at this point in the history
Closes dart-lang/pool#6
  • Loading branch information
nex3 authored May 17, 2017
1 parent 11e3f8c commit c289d1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkgs/pool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3.1

* Fix the type annotation of `Pool.withResource()` to indicate that it takes
`() -> FutureOr<T>`.

## 1.3.0

* Add a `Pool.done` getter that returns the same future returned by
Expand Down
6 changes: 3 additions & 3 deletions pkgs/pool/lib/pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Pool {
/// Future.
///
/// The return value of [callback] is piped to the returned Future.
Future/*<T>*/ withResource/*<T>*/(/*=T*/ callback()) {
Future<T> withResource<T>(FutureOr<T> callback()) {
if (isClosed) {
throw new StateError(
"withResource() may not be called on a closed Pool.");
Expand All @@ -123,8 +123,8 @@ class Pool {
// synchronously in case the pool is closed immediately afterwards. Async
// functions have an asynchronous gap between calling and running the body,
// and [close] could be called during that gap. See #3.
return request().then/*<Future<T>>*/((resource) {
return new Future/*<T>*/.sync(callback).whenComplete(resource.release);
return request().then<Future<T>>((resource) {
return new Future<T>.sync(callback).whenComplete(resource.release);
});
}

Expand Down
4 changes: 2 additions & 2 deletions pkgs/pool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: pool
version: 1.3.0
version: 1.3.1
author: Dart Team <misc@dartlang.org>
description: A class for managing a finite pool of resources.
homepage: https://github.com/dart-lang/pool
dependencies:
async: "^1.4.0"
stack_trace: ">=0.9.2 <2.0.0"
environment:
sdk: ">=1.9.0 <2.0.0"
sdk: ">=1.22.0 <2.0.0"
dev_dependencies:
fake_async: ">=0.1.0 <0.2.0"
test: ">=0.12.0 <0.13.0"

0 comments on commit c289d1c

Please sign in to comment.