queueLaneOf function

QueueLane queueLaneOf(
  1. Expression waited
)

Whose queue waited waits for, when a job body of the enclosing controller waits for it.

For a Solo the answer is QueueLane.own where ownQueueCall finds the call. close() and cancelAll() of any controller are QueueLane.own: they wait for every lane. In a SoloLanes the lane of the waited job is the lane field the call queues it in, _likes.enqueue(...), or the one a method of the controller queues it in, read from the method's body in the same file; the lane of the waiting body is the lane field whose enqueue takes it. Both seen and the same is QueueLane.own, both seen and different is QueueLane.other; anything else, a body of a child or of a handler of an accumulator included, is QueueLane.unknown.

Implementation

QueueLane queueLaneOf(Expression waited) {
  final call = queueCallOf(waited);
  if (call == null) return QueueLane.unknown;
  final jobOf = waited is PropertyAccess;
  final target = call.realTarget;
  if (target != null && target is! ThisExpression) {
    // A job queued in a lane right here: `_likes.enqueue(...).done`.
    final lane = jobOf ? _laneQueuedBy(call) : null;
    return lane == null ? QueueLane.unknown : _laneAgainst(lane, waited);
  }
  final own = _ownMethodOf(call);
  if (own == null) return QueueLane.unknown;
  final (method, owner) = own;
  if (!jobOf) {
    return isSolo(owner) || isSoloController(owner)
        ? QueueLane.own
        : QueueLane.unknown;
  }
  if (isSolo(owner)) {
    return _returnsSoloJob(call, method) ? QueueLane.own : QueueLane.unknown;
  }
  if (!isSoloController(owner)) return QueueLane.unknown;
  // A declared SoloJob does not name the lane, so the body is read always.
  final lane = _laneOfMethod(call, method);
  return lane == null ? QueueLane.unknown : _laneAgainst(lane, waited);
}