Fix: Throw ArgumentError if poolSize <= 0 (#24)
Fixes #20
diff --git a/lib/pool.dart b/lib/pool.dart
index a4a7d93..40a2580 100644
--- a/lib/pool.dart
+++ b/lib/pool.dart
@@ -79,6 +79,10 @@
/// all pending [request] futures will throw a [TimeoutException]. This is
/// intended to avoid deadlocks.
Pool(this._maxAllocatedResources, {Duration timeout}) : _timeout = timeout {
+ if (_maxAllocatedResources <= 0) {
+ throw ArgumentError('pool limit should be > 0');
+ }
+
if (timeout != null) {
// Start the timer canceled since we only want to start counting down once
// we've run out of available resources.
diff --git a/test/pool_test.dart b/test/pool_test.dart
index a156c52..66624cf 100644
--- a/test/pool_test.dart
+++ b/test/pool_test.dart
@@ -436,6 +436,11 @@
completer.completeError("oh no!");
});
});
+
+ test("throw error when pool limit <= 0", () {
+ expect(() => Pool(-1), throwsArgumentError);
+ expect(() => Pool(0), throwsArgumentError);
+ });
}
/// Returns a function that will cause the test to fail if it's called.