forEachBaggageItem method

void forEachBaggageItem(
  1. Function baggageHandler
)

ForeachBaggageItem grants access to all baggage items stored in the SpanContext. The handler function will be called for each baggage key/value pair. The ordering of items is not guaranteed.

The bool return value indicates if the handler wants to continue iterating through the rest of the baggage items; for example if the handler is trying to find some baggage item by pattern matching the name, it can return false as soon as the item is found to stop further iterations.

Implementation

void forEachBaggageItem(Function baggageHandler) {
  bool? continueIterations = true;
  for (dynamic key in this._baggage.keys) {
    continueIterations = baggageHandler(this._baggage[key]);
    if (!continueIterations!) {
      return;
    }
  }
}