take method

Future<T> take({
  1. Duration? timeout = const Duration(seconds: 30),
})

Takes an item from the pool.

After the item is no longer needed, it is required to give it back to the pool using give to make it available again. To avoid leaks, consider using use instead of take and give.

If the pool is not filled to the target size yet, a new item is created using the _createItem delegate. If the pool has reached its target size but all elements are taken, the request for an item is queued and completed as soon as an element becomes available again.

The timeout can be set to null, which means never. In the worst case, this method can take up to timeout + checkIsLiveTimeout to complete with an item or an error.

Implementation

Future<T> take({Duration? timeout = const Duration(seconds: 30)}) async {
  return await _takeSemaphore.runLocked(() async {
    return await _takeInternal(timeout);
  });
}