write method

void write(
  1. String data
)

Queues data to be written to the terminal.

Returns immediately - genuinely so, unlike calling _drain inline would: starting the drain on a microtask instead lets a burst of synchronous write() calls (a tight producer loop, or a sync StreamController delivering several chunks in one native callback) all land in the queue before the first pass looks at it, instead of each call racing its own one-chunk drain to completion.

Implementation

void write(String data) {
  if (_disposed || data.isEmpty) return;
  _pending.addLast(data);
  if (!_draining) {
    _draining = true;
    scheduleMicrotask(() => unawaited(_drain()));
  }
}