Skip to content

Commit 2d26f08

Browse files
committed
a better ok http default
1 parent 457c564 commit 2d26f08

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

impl/java/client/src/main/kotlin/br/com/guiabolso/events/client/http/OkHttpClientAdapter.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
77
import kotlinx.coroutines.suspendCancellableCoroutine
88
import okhttp3.Call
99
import okhttp3.Callback
10+
import okhttp3.Dispatcher
1011
import okhttp3.OkHttpClient
1112
import okhttp3.Request
1213
import okhttp3.RequestBody.Companion.toRequestBody
@@ -38,7 +39,9 @@ suspend fun Call.executeAsync(): Response =
3839
)
3940
}
4041

41-
class OkHttpClientAdapter(private val okHttpClient: OkHttpClient = OkHttpClient.Builder().build()) : HttpClientAdapter {
42+
class OkHttpClientAdapter(
43+
private val okHttpClient: OkHttpClient = okHttpClient()
44+
) : HttpClientAdapter {
4245
private val clients = ConcurrentHashMap<Long, OkHttpClient>()
4346

4447
override suspend fun suspendPost(
@@ -119,3 +122,10 @@ class OkHttpClientAdapter(private val okHttpClient: OkHttpClient = OkHttpClient.
119122
}
120123
}
121124
}
125+
126+
@Suppress("MagicNumber")
127+
private fun okHttpClient(): OkHttpClient = OkHttpClient.Builder().dispatcher(
128+
Dispatcher().apply {
129+
maxRequestsPerHost = 32
130+
}
131+
).build()

0 commit comments

Comments
 (0)