dispose method

Future<void> dispose()

Implementation

Future<void> dispose() async {
  if (_disposed) {
    return;
  }
  _disposed = true;
  await _streamSub.cancel();
  _outstandingRequests.forEach((id, request) {
    request.completeError(RPCError(
      request.method,
      RPCErrorKind.kServerError.code,
      'Service connection disposed',
    ));
  });
  _outstandingRequests.clear();
  final handler = _disposeHandler;
  if (handler != null) {
    await handler();
  }
  assert(!_onDoneCompleter.isCompleted);
  _onDoneCompleter.complete();
}