Support cancelling RootCommand
This commit is contained in:
@@ -420,14 +420,20 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
|
|||||||
Log.e(command.javaClass.simpleName, "Unexpected exception in RootCommandOneWay", e)
|
Log.e(command.javaClass.simpleName, "Unexpected exception in RootCommandOneWay", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is RootCommand<*> -> defaultWorker.launch {
|
is RootCommand<*> -> {
|
||||||
val result = try {
|
val commandJob = Job()
|
||||||
val result = command.execute();
|
cancellables[callback] = { commandJob.cancel() }
|
||||||
{ output.pushResult(callback, result) }
|
defaultWorker.launch(commandJob) {
|
||||||
} catch (e: Throwable) {
|
val result = try {
|
||||||
{ output.pushThrowable(callback, e) }
|
val result = command.execute();
|
||||||
|
{ output.pushResult(callback, result) }
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
{ output.pushThrowable(callback, e) }
|
||||||
|
} finally {
|
||||||
|
cancellables.remove(callback)
|
||||||
|
}
|
||||||
|
withContext(callbackWorker) { result() }
|
||||||
}
|
}
|
||||||
withContext(callbackWorker) { result() }
|
|
||||||
}
|
}
|
||||||
is RootCommandChannel<*> -> defaultWorker.launch {
|
is RootCommandChannel<*> -> defaultWorker.launch {
|
||||||
val result = try {
|
val result = try {
|
||||||
|
|||||||
Reference in New Issue
Block a user