Skip to content

Commit

Permalink
Close cache and connnections on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfeo committed Jan 3, 2023
1 parent b3bcf0f commit 611c406
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ var accessToken: () -> String = {
}

/**
* Shutdown the internal OkHttp client, releasing resources and allowing the program to finish
* before the client's idle timeout.
* Shutdown the internal client, releasing resources and allowing the program to
* finish before the client's idle timeout.
*
* https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/#shutdown-isnt-necessary
*/
fun shutdown() {
okHttpClient.dispatcher.executorService.shutdownNow()
okHttpClient.run {
dispatcher.executorService.shutdown()
connectionPool.evictAll();
cache?.close();
}
}

/**
Expand Down

0 comments on commit 611c406

Please sign in to comment.