bindScope method

void bindScope(
  1. ZenithTenantScope scope
)

Binds the currently open handle, once, to this scope's async cleanup.

Implementation

void bindScope(ZenithTenantScope scope) {
  if (scope.isClosing || scope.isDisposed) {
    throw StateError('Scope is closing');
  }
  final handle = _handles[scope.id];
  if (handle == null) throw StateError('Acquire a connection before binding');
  final owner = _owners[handle];
  if (owner != null && !identical(owner, scope)) {
    throw StateError('Connection is still owned by another scope');
  }
  if (owner == null) {
    _owners[handle] = scope;
    scope.onDisposeAsync(() => _releaseOwned(scope.id, handle));
  }
}