checkPoolSize method

FutureOr<bool> checkPoolSize(
  1. int minSize,
  2. int maxSize,
  3. int checkInvalidsIntervalMs
)
inherited

Implementation

FutureOr<bool> checkPoolSize(
    int minSize, int maxSize, int checkInvalidsIntervalMs) {
  var poolSize = this.poolSize;

  if (poolSize <= minSize) {
    if (lastCheckPoolElapsedTimeMs > checkInvalidsIntervalMs) {
      return removeInvalidElementsFromPool(checkUsage: false);
    } else {
      return true;
    }
  }

  if (poolSize > maxSize) {
    return removeInvalidElementsFromPool().resolveMapped((_) {
      var excess = this.poolSize - maxSize;
      _logPool.info(
          "Removing excess> poolSize: $poolSize ; maxSize: $maxSize ; excess: $excess");
      removeElementsFromPool(excess);
      return true;
    });
  }

  if (lastCheckPoolElapsedTimeMs > checkInvalidsIntervalMs) {
    return removeInvalidElementsFromPool();
  } else {
    return true;
  }
}