close method

Future<void> close({
  1. Duration timeout = const Duration(seconds: 15),
})

Closes every client, waits for each to report it is closed (up to timeout), then stops the receive isolate. Call before the process exits when you can (e.g. on desktop quit).

Implementation

Future<void> close({Duration timeout = const Duration(seconds: 15)}) async {
  if (_closed) return;
  await Future.wait([
    for (final client in _clients.values.toList())
      client.close(timeout: timeout),
  ]);
  _closed = true;
  _failPending(const TdClientClosedException(0));
  await _stopWorker();
  await _errors.close();
  if (identical(_instance, this)) _instance = null;
}