releaseConnection method
Closes the cached handle and cancels any in-flight acquisition for this ID.
Implementation
Future<void> releaseConnection(String tenantId) {
final existing = _releasing[tenantId];
if (existing != null) return existing;
final completion = Completer<void>();
_releasing[tenantId] = completion.future;
_generation[tenantId] = (_generation[tenantId] ?? 0) + 1;
final pending = _pending.remove(tenantId);
final handle = _handles.remove(tenantId);
if (handle != null) _owners.remove(handle);
Future.wait<void>([
if (handle != null && handle.isOpen) Future<void>.sync(handle.close),
if (pending != null) _waitForCancelledOpen(pending),
]).then(
(_) {
_releasing.remove(tenantId);
completion.complete();
},
onError: (Object error, StackTrace stack) {
_releasing.remove(tenantId);
completion.completeError(error, stack);
},
);
return completion.future;
}