Downgrade coroutines until Kotlin 1.4

This commit is contained in:
Mygod
2020-07-18 03:41:50 +08:00
parent 07a63f77c1
commit a90df1b88c
2 changed files with 13 additions and 12 deletions

View File

@@ -476,34 +476,35 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
cancellables[callback] = { commandJob.cancel() }
defaultWorker.launch(commandJob) {
val result = try {
val result = command.execute();
{ output.pushResult(callback, result) }
val result = command.execute()
withContext(callbackWorker + NonCancellable) { output.pushResult(callback, result) }
} catch (e: Throwable) {
{ output.pushThrowable(callback, e) }
withContext(callbackWorker + NonCancellable) { output.pushThrowable(callback, e) }
} finally {
cancellables.remove(callback)
}
cancellables.remove(callback)
withContext(callbackWorker + NonCancellable) { result() }
}
}
is RootCommandChannel<*> -> defaultWorker.launch {
val result = try {
try {
coroutineScope {
command.create(this).also {
cancellables[callback] = { it.cancel() }
}.consumeEach { result ->
withContext(callbackWorker) { output.pushResult(callback, result) }
}
};
@Suppress("BlockingMethodInNonBlockingContext") {
}
@Suppress("BlockingMethodInNonBlockingContext")
withContext(callbackWorker + NonCancellable) {
output.writeByte(CHANNEL_CONSUMED)
output.writeLong(callback)
output.flush()
}
} catch (e: Throwable) {
{ output.pushThrowable(callback, e) }
withContext(callbackWorker + NonCancellable) { output.pushThrowable(callback, e) }
} finally {
cancellables.remove(callback)
}
cancellables.remove(callback)
withContext(callbackWorker + NonCancellable) { result() }
}
is Shutdown -> break@loop
else -> throw IllegalArgumentException("Unrecognized input: $command")