close method Null safety

Future close()

Closes the pool so that no more resources are requested.

Existing resource requests remain unchanged.

Any resources that are marked as releasable using PoolResource.allowRelease are released immediately. Once all resources have been released and any onRelease callbacks have completed, the returned future completes successfully. If any onRelease callback throws an error, the returned future completes with that error.

This may be called more than once; it returns the same Future each time.


Future close() => _closeMemo.runOnce(() {
      if (_closeGroup != null) return _closeGroup!.future;


      _closeGroup = FutureGroup();
      for (var callback in _onReleaseCallbacks) {

      _allocatedResources -= _onReleaseCallbacks.length;

      if (_allocatedResources == 0) _closeGroup!.close();
      return _closeGroup!.future;