flush static method

void flush()

Implementation

static void flush() {
  _timer?.cancel();
  _timer = null;
  if (_buffer.isEmpty) return;
  String text = _buffer.toString();
  _buffer.clear();
  try {
    writer(text);
  } catch (_) {
    // a failed write (eg. closed stdout) must not crash the app.
    // try stderr once, so the lines are not lost without a trace.
    // We can not know how much of the text the writer wrote before it
    // threw, so a few lines can appear twice. This is on purpose: a
    // double line is better than a lost line.
    try {
      stderr.write(text);
    } catch (_) {}
  }
}