cvRunArena<R> function

R cvRunArena<R>(
  1. R computation(
    1. Arena arena
    ), [
  2. Allocator wrappedAllocator = calloc,
  3. bool keep = false
])

Implementation

R cvRunArena<R>(
  R Function(Arena arena) computation, [
  ffi.Allocator wrappedAllocator = calloc,
  bool keep = false,
]) {
  final arena = Arena(wrappedAllocator);
  bool isAsync = false;
  try {
    final result = computation(arena);
    if (result is Future) {
      isAsync = true;
      return result.whenComplete(arena.releaseAll) as R;
    }
    return result;
  } finally {
    if (!isAsync && !keep) {
      arena.releaseAll();
    }
  }
}