Skip to content

Commit

Permalink
fix: dispatch on main for sdk methods and dispatch network calls on I…
Browse files Browse the repository at this point in the history
…O, increase timeout to 30 seconds
  • Loading branch information
jsalaber committed Nov 17, 2023
1 parent 41307cd commit 2b6bfae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.devcycle.sdk.android.util.JSONMapper
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import java.util.concurrent.TimeUnit
import kotlin.time.Duration

internal class DVCApiClient {
private val okBuilder: OkHttpClient.Builder = OkHttpClient.Builder()
Expand All @@ -14,6 +16,7 @@ internal class DVCApiClient {

fun initialize(baseUrl: String, context: Context): DVCApi {
okBuilder.addInterceptor(NetworkConnectionInterceptor(context))
okBuilder.connectTimeout(30, TimeUnit.SECONDS)
return adapterBuilder
.baseUrl(baseUrl)
.client(okBuilder.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DevCycleClient private constructor(
eventsUrl: String,
private val customLifecycleHandler: Handler? = null,
private val coroutineScope: CoroutineScope = MainScope(),
private val coroutineContext: CoroutineContext = Dispatchers.Default
private val coroutineContext: CoroutineContext = Dispatchers.Main
) {
private var config: BucketedUserConfig? = null
private var eventSource: EventSource? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ internal class Request constructor(sdkKey: String, apiBaseUrl: String, eventsBas
val maxDelay = 10000L

flow {
DevCycleLogger.d("Current Thread for the flow: ${Thread.currentThread().name}")
val response = api.getConfigJson(sdkKey, map)
emit(getResponseHandler(response))
}
.flowOn(Dispatchers.Default)
.flowOn(Dispatchers.IO)
.retryWhen { cause, attempt ->
if (cause is DVCRequestException) {
if (!cause.isRetryable || attempt > 4) {
Expand Down

0 comments on commit 2b6bfae

Please sign in to comment.