Skip to content

Commit

Permalink
feat: add timeout to the http client (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko authored Jul 30, 2024
1 parent 52200f4 commit eab3985
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Confidence/src/main/java/com/spotify/confidence/Confidence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

internal const val SDK_ID = "SDK_ID_KOTLIN_CONFIDENCE"

Expand Down Expand Up @@ -293,14 +294,16 @@ object ConfidenceFactory {
* @param region region of operation.
* @param dispatcher coroutine dispatcher.
* @param loggingLevel allows to print warnings or debugging information to the local console.
* @param timeoutMillis sets a timeout for completing an HTTP call. Defaults to 10 seconds
*/
fun create(
context: Context,
clientSecret: String,
initialContext: Map<String, ConfidenceValue> = mapOf(),
region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
dispatcher: CoroutineDispatcher = Dispatchers.IO,
loggingLevel: LoggingLevel = LoggingLevel.WARN
loggingLevel: LoggingLevel = LoggingLevel.WARN,
timeoutMillis: Long = 10000
): Confidence {
val debugLogger: DebugLogger? = if (loggingLevel == LoggingLevel.NONE) {
null
Expand All @@ -324,7 +327,9 @@ object ConfidenceFactory {
val flagResolver = RemoteFlagResolver(
clientSecret = clientSecret,
region = region,
httpClient = OkHttpClient(),
httpClient = OkHttpClient.Builder()
.callTimeout(timeoutMillis, TimeUnit.MILLISECONDS)
.build(),
dispatcher = dispatcher,
sdkMetadata = SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION)
)
Expand Down

0 comments on commit eab3985

Please sign in to comment.