Anton Afanasev
11/29/2021, 3:11 PMreconnectFun
. The idea is to trigger that function after some delay (which is incrementing from one attempt to another). The reconnectFun
is passed from the parent class that is responsible for network error listening.
I understand that my problem is that I mutate the attempts
from with in the other thread, as well I call the reconnectFun
but what is the proper way of doing something similar?
internal class ReconnectionManager {
private var attempts = 0
private val dispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())
fun reconnect(reconnectFun: () -> Unit) {
dispatcher.launch {
delay(attempts * 1000)
withContext(Dispatchers.Default) {
attempts++
reconnectFun()
}
}
}
}
Stefan Oltmann
11/29/2021, 3:57 PMthis.ensureNeverFrozen()
in the init block of your ReconnectionManager 😄Stefan Oltmann
11/29/2021, 4:02 PMKonstantin Tskhovrebov
11/29/2021, 7:34 PMinline fun mainContinuation(
noinline block: () -> Unit
): () -> Unit = Continuation0(
block,
staticCFunction { invokerArg ->
if (NSThread.isMainThread()) {
invokerArg!!.callContinuation0()
} else {
dispatch_sync_f(dispatch_get_main_queue(), invokerArg, staticCFunction { args ->
args!!.callContinuation0()
})
}
},
true
)
Anton Afanasev
11/30/2021, 5:56 PMAnton Afanasev
11/30/2021, 5:56 PMStefan Oltmann
12/01/2021, 7:28 AM