close method

  1. @override
Future close(
  1. String? correlationId
)

Closes component and frees used resources.

  • correlationId (optional) transaction id to trace execution through call chain. Returns Future that receives error or null no errors occured.

Implementation

@override
Future close(String? correlationId) async {
  if (!_opened) {
    return;
  }

  if (_connection == null) {
    throw InvalidStateException(
        correlationId, 'NO_CONNECTION', 'MQTT connection is missing');
  }

  if (_localConnection) {
    await _connection!.close(correlationId);
  }

  if (_subscribed) {
    // Unsubscribe from the topic
    var topic = getTopic();
    await _connection!.unsubscribe(topic, this);
  }

  _messages = [];
  _opened = false;
  _receiver = null;
}