retain method

void retain(
  1. ResourceControl? control
)

Implementation

void retain(ResourceControl? control) {
  if (_released) throw StateError('Resource operation is released.');
  if (control == null ||
      identical(control, _group.exempt) ||
      _group.leases.containsKey(control)) {
    return;
  }
  _group.leases[control] = control.retainOperation();
  final notices = _group.streams?.toList(growable: false);
  if (notices == null) return;
  for (final notice in notices) {
    if (!notice.operation.isReleased) notice.attach(control);
  }
  if (!_released && control.state != ResourceState.open) {
    control._cancelStreams(notices);
  }
}