using<T> method

T using<T>(
  1. T resource,
  2. void releaseCallback(
    1. T
    )
)

Registers resource in this arena.

Executes releaseCallback on releaseAll.

Returns resource again, to allow for easily inserting arena.using(resource, ...) where the resource is allocated.

Implementation

T using<T>(T resource, void Function(T) releaseCallback) {
  _ensureInUse();
  releaseCallback = Zone.current.bindUnaryCallback(releaseCallback);
  _managedResourceReleaseCallbacks.add(() => releaseCallback(resource));
  return resource;
}