current property

ZonedWork<Object?>? get current

Returns an instance of the current ZonedWork or null.

Implementation

static ZonedWork<Object?>? get current {
  final zone = Zone.current;
  if (identical(zone, _lastZone)) {
    return _lastZonedWork;
  }

  _lastZone = zone;
  _lastZonedWork = null;
  if (identical(zone, Zone.root)) {
    return null;
  }

  // Look up the key in the zone and in the parent zone.
  if (zone[_key] case final ZonedWork<Object?> work) {
    _lastZonedWork = work;
    return work;
  }

  var parent = zone.parent?.parent;
  if (parent == null) {
    return null;
  }

  if (parent[_key] case final ZonedWork<Object?> work) {
    _lastZonedWork = work;
    return work;
  }

  parent = zone.parent?.parent;
  while (parent != null) {
    if (parent[_key] case final ZonedWork<Object?> work) {
      _lastZonedWork = work;
      return work;
    }

    parent = zone.parent?.parent;
  }

  return null;
}