zoneArena top-level property

Arena get zoneArena

A zone-specific Arena.

Asynchronous computations can share a Arena. Use withZoneArena to create a new zone with a fresh Arena, and that arena will then be released automatically when the function passed to withZoneArena completes. All code inside that zone can use zoneArena to access the arena.

The current arena must not be accessed by code which is not running inside a zone created by withZoneArena.

Implementation

Arena get zoneArena {
  final arenaHolder = Zone.current[#_arena] as List<Arena>?;
  if (arenaHolder == null) {
    throw StateError('Not inside a zone created by `useArena`');
  }
  if (arenaHolder.isNotEmpty) {
    return arenaHolder.single;
  }
  throw StateError('Arena has already been cleared with releaseAll.');
}