write method

Future<void> write(
  1. T chunk
)

Writes chunk to the stream. Fails with DataStreamErrorReason.AlreadyClosed once close has been called.

Implementation

Future<void> write(T chunk) async {
  if (_closing != null) {
    throw DataStreamError(reason: DataStreamErrorReason.AlreadyClosed, message: 'Stream writer is closed');
  }
  _writesInFlight++;
  try {
    await writableStream.write(chunk);
  } finally {
    _writesInFlight--;
    if (_writesInFlight == 0) {
      _writesDone?.complete();
      _writesDone = null;
    }
  }
}