1
1
package com.statsig.sdk
2
2
3
3
import com.google.gson.Gson
4
- import kotlinx.coroutines.CoroutineExceptionHandler
5
- import kotlinx.coroutines.CoroutineScope
6
- import kotlinx.coroutines.Dispatchers
7
- import kotlinx.coroutines.launch
4
+ import kotlinx.coroutines.*
8
5
import okhttp3.Call
9
6
import okhttp3.Callback
10
7
import okhttp3.MediaType.Companion.toMediaType
@@ -25,6 +22,7 @@ internal class ErrorBoundary(private val apiKey: String, private val options: St
25
22
OkHttpClient ()
26
23
}
27
24
internal var diagnostics: Diagnostics ? = null
25
+ private val coroutineScope = CoroutineScope (this .getNoopExceptionHandler() + Dispatchers .IO )
28
26
29
27
private companion object {
30
28
val MEDIA_TYPE = " application/json; charset=utf-8" .toMediaType()
@@ -51,6 +49,7 @@ internal class ErrorBoundary(private val apiKey: String, private val options: St
51
49
fun shutdown () {
52
50
// Properly close the OkHttpClient to release resources
53
51
try {
52
+ coroutineScope.cancel()
54
53
client.dispatcher.executorService.shutdown()
55
54
client.connectionPool.evictAll()
56
55
client.cache?.close()
@@ -92,7 +91,7 @@ internal class ErrorBoundary(private val apiKey: String, private val options: St
92
91
93
92
internal fun logException (tag : String , ex : Throwable , configName : String? = null, extraInfo : String? = null, bypassDedupe : Boolean = false) {
94
93
try {
95
- CoroutineScope ( this .getNoopExceptionHandler() + Dispatchers . IO ) .launch {
94
+ coroutineScope .launch {
96
95
if (options.localMode || options.disableAllLogging) {
97
96
return @launch
98
97
}
0 commit comments