close method

void close()

Close a mailbox.

If mailbox already contains a message then close will drop the message.

Implementation

void close() => _mutex.runLocked(() {
      if (_mailbox.ref.state == _stateFull && _mailbox.ref.bufferLength > 0) {
        malloc.free(_mailbox.ref.buffer);
      }

      _mailbox.ref.state = _stateClosed;
      _mailbox.ref.buffer = nullptr;
      _mailbox.ref.bufferLength = 0;

      _condVar.notify();
    });