Skip to content

Commit 13de879

Browse files
listepokevmoo
authored andcommitted
Fix: Throw ArgumentError if poolSize <= 0 (#24)
Fixes flutter#20
1 parent 155df64 commit 13de879

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/pool.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class Pool {
7979
/// all pending [request] futures will throw a [TimeoutException]. This is
8080
/// intended to avoid deadlocks.
8181
Pool(this._maxAllocatedResources, {Duration timeout}) : _timeout = timeout {
82+
if (_maxAllocatedResources <= 0) {
83+
throw ArgumentError('pool limit should be > 0');
84+
}
85+
8286
if (timeout != null) {
8387
// Start the timer canceled since we only want to start counting down once
8488
// we've run out of available resources.

test/pool_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ void main() {
436436
completer.completeError("oh no!");
437437
});
438438
});
439+
440+
test("throw error when pool limit <= 0", () {
441+
expect(() => Pool(-1), throwsArgumentError);
442+
expect(() => Pool(0), throwsArgumentError);
443+
});
439444
}
440445

441446
/// Returns a function that will cause the test to fail if it's called.

0 commit comments

Comments
 (0)