Skip to content

Commit

Permalink
Fix: Throw ArgumentError if poolSize <= 0 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
listepo authored and kevmoo committed Jan 7, 2019
1 parent 155df64 commit 13de879
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class Pool {
/// 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.
Expand Down
5 changes: 5 additions & 0 deletions test/pool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ void main() {
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.
Expand Down

0 comments on commit 13de879

Please sign in to comment.