put method

void put(
  1. Uint8List message
)

Place a message into the mailbox if has space for it. If mailbox already contains a message the put will throw a MailBoxFullException exception. If mailbox is closed then put will throw MailBoxClosedException.

Implementation

/// If mailbox already contains a message the [put] will
/// throw a [MailBoxFullException] exception.
///  If  mailbox is closed then [put] will
/// throw [MailBoxClosedException].
void put(Uint8List message) {
  _mutex.runLocked(() {
    assert(_mailbox.ref.magic == _magic, 'Mailbox memory corrupted/UAF');
    if (_isClosed) {
      throw MailBoxClosedException();
    }

    if (_isFull) {
      throw MailBoxFullException();
    }
    final buffer = message.isEmpty ? nullptr : _toBuffer(message);
    _mailbox.ref.count = 1;
    _mailbox.ref.buffer = buffer;
    _mailbox.ref.bufferLength = message.length;
    _condVar.notify();
  });
}