Skip to content

Commit

Permalink
Share clientBuilder between Config constructor calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfeo committed May 22, 2023
1 parent 5e48330 commit 6876d6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ data class Config(
* share resources such as thread pools with another [OkHttpClient], useful for full Kotlin projects
* and rarely needed for scripting. See [OkHttpClient] for all that is shared.
*/
val clientBuilder: OkHttpClient.Builder =
OkHttpClient.Builder(),
val clientBuilder: OkHttpClient.Builder = basicOkHttpClient.newBuilder(),

/**
* Maximum amount of concurrent requests allowed. Further requests will be queued. By default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ import java.time.Duration
import java.util.logging.Level
import java.util.logging.Logger

/**
* Base instance just so that multiple created [Config]s will share resources by default.
*/
internal val basicOkHttpClient by lazy {
OkHttpClient.Builder().build()
}

/**
* Builds the final `OkHttpClient` with a `Config`.
*/
internal fun buildOkHttpClient(
config: Config,
) = with(config.clientBuilder) {
Expand Down

0 comments on commit 6876d6b

Please sign in to comment.