android, desktop: move function to different thread
This commit is contained in:
parent
97fbf2b7fe
commit
fa9f5b3250
@ -451,7 +451,7 @@ object ChatController {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val msg = recvMsg(ctrl)
|
val msg = recvMsg(ctrl)
|
||||||
if (msg != null) processReceivedMsg(msg)
|
if (msg != null) withSingleThreadContext { processReceivedMsg(msg) }
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "ChatController recvMsg/processReceivedMsg exception: " + e.stackTraceToString());
|
Log.e(TAG, "ChatController recvMsg/processReceivedMsg exception: " + e.stackTraceToString());
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
@ -42,6 +42,8 @@ fun withLongRunningApi(slow: Long = Long.MAX_VALUE, deadlock: Long = Long.MAX_VA
|
|||||||
CoroutineScope(Dispatchers.Default).launch(block = { wrapWithLogging(action, it, slow = slow, deadlock = deadlock) })
|
CoroutineScope(Dispatchers.Default).launch(block = { wrapWithLogging(action, it, slow = slow, deadlock = deadlock) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun withSingleThreadContext(action: suspend CoroutineScope.() -> Unit) = withContext(singleThreadDispatcher, action)
|
||||||
|
|
||||||
private suspend fun wrapWithLogging(action: suspend CoroutineScope.() -> Unit, exception: java.lang.Exception, slow: Long = 10_000, deadlock: Long = 60_000) = coroutineScope {
|
private suspend fun wrapWithLogging(action: suspend CoroutineScope.() -> Unit, exception: java.lang.Exception, slow: Long = 10_000, deadlock: Long = 60_000) = coroutineScope {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
val job = launch {
|
val job = launch {
|
||||||
|
Loading…
Reference in New Issue
Block a user