description

# forEachEntry method Null safety

void forEachEntry (

1. void action(
   1. DoubleLinkedQueueEntry<E> element
   )

)

Calls `action` for each entry object of this double-linked queue.

Each element of the queue has an associated DoubleLinkedQueueEntry. This method iterates the entry objects from first to last and calls `action` with each object in turn.

The entry objects can also be accessed using firstEntry and lastEntry, and iterated using DoubleLinkedQueueEntry.nextEntry() and DoubleLinkedQueueEntry.previousEntry().

The `action` function can use methods on DoubleLinkedQueueEntry to remove the entry or it can insert elements before or after then entry. If the current entry is removed, iteration continues with the entry that was following the current entry when `action` was called. Any elements inserted after the current element before it is removed will not be visited by the iteration.

## Implementation

    void forEachEntry(void action(DoubleLinkedQueueEntry<E> element)) {
      _DoubleLinkedQueueEntry<E> entry =
          _sentinel._nextLink as _DoubleLinkedQueueEntry<E>;
      while (!identical(entry, _sentinel)) {
        _DoubleLinkedQueueElement<E> element =
            entry as _DoubleLinkedQueueElement<E>;
        _DoubleLinkedQueueEntry<E> next =
            element._nextLink as _DoubleLinkedQueueEntry<E>;
        // Remember both entry and entry._nextLink.
        // If someone calls `element.remove()` we continue from `next`.
        // Otherwise we use the value of entry._nextLink which may have been
        // updated.
        action(element);
        if (identical(this, entry._queue)) {
          next = entry._nextLink as _DoubleLinkedQueueEntry<E>;
        } else if (!identical(this, next._queue)) {
          throw ConcurrentModificationError(this);
        }
        entry = next;
      }
    }