Created
January 24, 2021 18:50
-
-
Save canergulgec/d01be037ae0e8e68456b20537a02f99c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object OkHttpProvider { | |
// Timeout for the network requests | |
private const val REQUEST_TIMEOUT = 3L | |
private var okHttpClient: OkHttpClient? = null | |
fun getOkHttpClient(): OkHttpClient { | |
return if (okHttpClient == null) { | |
val okHttpClient = OkHttpClient.Builder() | |
.readTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.connectTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS) | |
.build() | |
OkHttpProvider.okHttpClient = okHttpClient | |
okHttpClient | |
} else { | |
okHttpClient!! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment