Skip to content

Commit

Permalink
Downgrade coroutines until Kotlin 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Jul 17, 2020
1 parent 07a63f7 commit a90df1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mobile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dependencies {
implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0")
implementation("eu.chainfire:librootjava:1.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6")
testImplementation("junit:junit:4.13")
androidTestImplementation("androidx.room:room-testing:$roomVersion")
androidTestImplementation("androidx.test:runner:1.2.0")
Expand Down
23 changes: 12 additions & 11 deletions mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a90df1b

Please sign in to comment.