close method

void close({
  1. bool force = false,
})

Shuts down the HttpClient.

The HttpClient will be kept alive until all active connections are done. If force is true any active connections will be closed to immediately release all resources. These closed connections will receive an error event to indicate that the client was shut down. Trying to establish a new connection after calling close, will throw an Exception.

Implementation

void close({bool force = false}) {
  if (_stop) return;
  _stop = true;
  if (force) {
    // Deep copying the list because the original list may get modified
    // during the traversal as cronet sends onCancel callbacks.
    final requests = _requests.toList();
    for (final request in requests) {
      cronet.Cronet_UrlRequest_Cancel(request.requestPtr);
      request.callbackHandler.controller
          .addError(HttpException('HttpClient: Force Closed'));
    }
  }
}