5
5
package io.gitpod.jetbrains.remote
6
6
7
7
import com.intellij.codeWithMe.ClientId
8
+ import com.intellij.codeWithMe.asContextElement
8
9
import com.intellij.ide.BrowserUtil
9
10
import com.intellij.ide.CommandLineProcessor
10
11
import com.intellij.openapi.client.ClientKind
@@ -27,10 +28,7 @@ import io.netty.channel.ChannelHandlerContext
27
28
import io.netty.handler.codec.http.FullHttpRequest
28
29
import io.netty.handler.codec.http.QueryStringDecoder
29
30
import io.prometheus.client.exporter.common.TextFormat
30
- import kotlinx.coroutines.GlobalScope
31
- import kotlinx.coroutines.delay
32
- import kotlinx.coroutines.launch
33
- import kotlinx.coroutines.runBlocking
31
+ import kotlinx.coroutines.*
34
32
import org.jetbrains.ide.RestService
35
33
import org.jetbrains.io.response
36
34
import java.io.OutputStreamWriter
@@ -113,14 +111,12 @@ class GitpodCLIService : RestService() {
113
111
}
114
112
115
113
private fun withClient (request : FullHttpRequest , context : ChannelHandlerContext , action : suspend (project: Project ? ) -> Unit ): String? {
116
- GlobalScope .launch {
117
- getClientSessionAndProjectAsync().let { (session, project) ->
118
- ClientId .withClientId(session.clientId) {
119
- runBlocking {
120
- action(project)
121
- }
122
- sendOk(request, context)
123
- }
114
+ val scope = CoroutineScope (Dispatchers .Default )
115
+ scope.launch {
116
+ val (session, project) = getClientSessionAndProjectAsync()
117
+ withContext(session.clientId.asContextElement()) {
118
+ action(project)
119
+ sendOk(request, context)
124
120
}
125
121
}
126
122
return null
0 commit comments