From 3b7237fb4f8ffe83b18cf9efa76b7e58ca6cd068 Mon Sep 17 00:00:00 2001 From: tkasatkin Date: Thu, 11 Dec 2025 19:17:12 +0300 Subject: [PATCH] Being able to configure blocking http calls dispatcher --- kbdd/src/main/kotlin/ru/fix/kbdd/rest/Rest.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kbdd/src/main/kotlin/ru/fix/kbdd/rest/Rest.kt b/kbdd/src/main/kotlin/ru/fix/kbdd/rest/Rest.kt index a567035..d354cc6 100644 --- a/kbdd/src/main/kotlin/ru/fix/kbdd/rest/Rest.kt +++ b/kbdd/src/main/kotlin/ru/fix/kbdd/rest/Rest.kt @@ -25,6 +25,7 @@ import ru.fix.kbdd.json.json import ru.fix.kbdd.map.MapDsl import java.io.InputStream import java.util.concurrent.Executors +import kotlin.coroutines.CoroutineContext private val log = KotlinLogging.logger { } @@ -43,14 +44,29 @@ object Rest { private val lastResponse = ThreadLocal() - var threadPoolSize = 10 var restAssuredConfigCustomizer: RestAssuredConfig.() -> RestAssuredConfig = { this } - private val dispatcher by lazy { - Executors.newFixedThreadPool(threadPoolSize).asCoroutineDispatcher() + + var defaultBlockingThreadPoolSize = 10 + @Deprecated("Old alias for backward compatibility", ReplaceWith("defaultBlockingThreadPoolSize")) + var threadPoolSize: Int + get() = defaultBlockingThreadPoolSize + set(value) { + defaultBlockingThreadPoolSize = value + } + + /** + * Being able to completely override dispatcher for blocking http calls. + * By default, it creates fixed thread pool with [defaultBlockingThreadPoolSize] threads. + */ + var httpBlockingCallsDispatcherProvider: () -> CoroutineContext = { + Executors.newFixedThreadPool(defaultBlockingThreadPoolSize).asCoroutineDispatcher() + CoroutineExceptionHandler { _, thr -> log.error(thr) {} } } + private val dispatcher: CoroutineContext by lazy { + httpBlockingCallsDispatcherProvider() + } + /** * Provides DSL for building HTTP request