mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(build-service,tooling-api): Gradle Daemon and ToolingAPI server is not stopped properly
The Tooling API server (which is executed in a separate process) was not being stopped properly after IToolingApiServer.shutdown() was called. As a result, the Gradle daemon started by the tooling API was not stopped as well. This commit fixes this issue by properly implementing the shutdown() call in Tooling API. Now, when the user closes a project and the GradleBuildService is destroyed, the Tooling API server stops the Gradle daemon(s) and then shutdowns itself.
This commit is contained in:
@@ -21,6 +21,7 @@ import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancel
|
||||
import java.io.InterruptedIOException
|
||||
|
||||
/**
|
||||
* Calls [CoroutineScope.cancel] only if a job is active in the scope.
|
||||
@@ -39,7 +40,22 @@ fun CoroutineScope.cancelIfActive(message: String, cause: Throwable? = null) =
|
||||
*/
|
||||
fun CoroutineScope.cancelIfActive(exception: CancellationException? = null) {
|
||||
val job = coroutineContext[Job]
|
||||
if (job?.isActive == true) {
|
||||
cancel(exception)
|
||||
job?.cancel(exception)
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given [action] and re-throws the [Throwable] if this [Throwable] is thrown for
|
||||
* cancellation or interruption purposes.
|
||||
*
|
||||
* @param action The action to run if this [Throwable] was cancelled or interrupted.
|
||||
*/
|
||||
inline fun Throwable.ifCancelledOrInterrupted(suppress: Boolean = false, action: () -> Unit) {
|
||||
when (this) {
|
||||
is CancellationException,
|
||||
is InterruptedException,
|
||||
is InterruptedIOException -> {
|
||||
action()
|
||||
if (!suppress) { throw this }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user