use<R> method
Borrows a resource for action, returning it to the pool afterward even if
action throws. The usual entry point — it pairs acquire/release so a
resource can never leak. Throws StateError if the pool is closed.
Audited: 2026-06-12 11:26 EDT
Implementation
Future<R> use<R>(Future<R> Function(T resource) action) async {
final T resource = await acquire();
try {
return await action(resource);
} finally {
release(resource);
}
}