close
Initiates the shutdown process for the HttpClient. This is a non-blocking call, which means it returns immediately and begins the client closure in the background.
Usage
val client = HttpClient()
client.close()
client.coroutineContext.job.join() // Waits for complete termination if necessaryContent copied to clipboard
Important Notes
Non-blocking:
close()only starts the closing process and does not wait for it to complete.Coroutine Context: To wait for all client resources to be freed, use
client.coroutineContext.job.join()orclient.coroutineContext.cancel()to terminate ongoing tasks.Manual Engine Management: If a custom
enginewas manually created, it must be closed explicitly after callingclient.close()to release all resources.
Example with custom engine management:
val engine = HttpClientEngine() // Custom engine instance
val client = HttpClient(engine)
client.close()
engine.close() // Ensure manually created engine is also closedContent copied to clipboard