sendOutput method

void sendOutput(
  1. String category,
  2. String message, {
  3. int? variablesReference,
  4. @Deprecated('parseStackFrames has no effect, stack frames are always parsed') bool? parseStackFrames,
})

Sends an OutputEvent (without a newline, since calls to this method may be using buffered data that is not split cleanly on newlines).

To ensure output is sent to the client in the correct order even if processing stack frames requires async calls, this function will insert output events into a queue and only send them when previous calls have been completed.

Implementation

void sendOutput(
  String category,
  String message, {
  int? variablesReference,
  @Deprecated(
      'parseStackFrames has no effect, stack frames are always parsed')
  bool? parseStackFrames,
}) async {
  // Reserve our place in the queue be inserting a future that we can complete
  // after we have sent the output event.
  final completer = Completer<void>();
  final previousEvent = _lastOutputEvent ?? Future.value();
  _lastOutputEvent = completer.future;

  try {
    final outputEvents = await _buildOutputEvents(
      category,
      message,
      variablesReference: variablesReference,
    );

    // Chain our sends onto the end of the previous one, and complete our Future
    // once done so that the next one can go.
    await previousEvent;
    outputEvents.forEach(sendEvent);
  } finally {
    completer.complete();
  }
}