close method

Future<void> close()

Close the Transport.

Implementation

Future<void> close() async {
  if (_closed) {
    return;
  }

  _logger.debug('close()');

  _closed = true;

  // TODO: close task handler.

  // Close the handler.
  await _handler.close();

  // Close all Producers.
  for (Producer producer in _producers.values) {
    producer.transportClosed();
  }
  _producers.clear();

  // Close all Consumers.
  for (Consumer consumer in _consumers.values) {
    consumer.transportClosed();
  }
  _consumers.clear();

  // Close all DataProducers.
  for (DataProducer dataProducer in _dataProducers.values) {
    dataProducer.transportClosed();
  }
  _dataProducers.clear();

  // Close all DataConsumers.
  for (DataConsumer dataConsumer in _dataConsumers.values) {
    dataConsumer.transportClosed();
  }
  _dataConsumers.clear();

  // Emit observer event.
  _observer.safeEmit('close');
}