takeNow property

T get takeNow

Takes from the available set of objects without attempting to grow, will throw an exception if no objects are available instead of growing.

Implementation

T get takeNow {
  if (_available.isEmpty) {
    throw Exception('No objects available!');
  }

  final t = _available.first;
  if (!_available.remove(t)) {
    throw Exception('Trying to take an object that is not available!');
  }

  if (!_inUse.add(t)) {
    throw Exception('Trying to take an object that is already in use!');
  }

  return t;
}