Pool constructor
Creates a new pool with the given limit on how many resources may be allocated at once.
If timeout
is passed, then if that much time passes without any activity
all pending request futures will throw a TimeoutException. This is
intended to avoid deadlocks.
Implementation
Pool(this._maxAllocatedResources, {Duration? timeout}) : _timeout = timeout {
if (_maxAllocatedResources <= 0) {
throw ArgumentError.value(_maxAllocatedResources, 'maxAllocatedResources',
'Must be greater than zero.');
}
if (timeout != null) {
// Start the timer canceled since we only want to start counting down once
// we've run out of available resources.
_timer = RestartableTimer(timeout, _onTimeout)..cancel();
}
}