dispose method

  1. @mustCallSuper
void dispose({
  1. bool keepHttpClientAlive = false,
})

Closes the service and cleans up any resources associated with it. It is important to call dispose() to release any resources that are being used by this REST service, such as the HTTP client.

If keepHttpClientAlive is set to true, the original HTTP client will be kept alive after calling dispose(). This can be useful if you are still using the same client and don't want to close it. However, it is important to note that keeping the HTTP client alive can consume resources, so you should only do this if necessary.

Implementation

@mustCallSuper

/// Closes the service and cleans up any resources associated with it.
/// It is important to call dispose() to release any resources that are being
/// used by this REST service, such as the HTTP client.
///
/// If [keepHttpClientAlive] is set to true, the original HTTP client will be
/// kept alive after calling dispose(). This can be useful if you are still
/// using the same client and don't want to close it. However, it is important
/// to note that keeping the HTTP client alive can consume resources, so you
/// should only do this if necessary.
void dispose({
  bool keepHttpClientAlive = false,
}) {
  final currentClient = client;
  if (keepHttpClientAlive && currentClient == config.client) return;
  if (currentClient is WrapperClient) {
    return currentClient.close(
      force: true,
      keepAliveHttpClient: keepHttpClientAlive ? config.client : null,
    );
  } else {
    return currentClient.close();
  }
}