Skip to content

Commit b83487d

Browse files
committed
Dispose the coroutine scope when is no longer needed
1 parent 244dde9 commit b83487d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.coder.gateway.icons.CoderIcons
77
import com.coder.gateway.models.RecentWorkspaceConnection
88
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
99
import com.intellij.ide.BrowserUtil
10+
import com.intellij.openapi.Disposable
1011
import com.intellij.openapi.actionSystem.AnActionEvent
1112
import com.intellij.openapi.components.service
1213
import com.intellij.openapi.project.DumbAwareAction
@@ -30,12 +31,13 @@ import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
3031
import com.jetbrains.rd.util.lifetime.Lifetime
3132
import kotlinx.coroutines.CoroutineScope
3233
import kotlinx.coroutines.Dispatchers
34+
import kotlinx.coroutines.cancel
3335
import kotlinx.coroutines.launch
3436
import java.awt.Dimension
3537
import javax.swing.JComponent
3638
import javax.swing.event.DocumentEvent
3739

38-
class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections {
40+
class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Disposable {
3941
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
4042
private val cs = CoroutineScope(Dispatchers.Main)
4143

@@ -137,4 +139,8 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections {
137139
border = JBUI.Borders.empty(12, 0, 0, 12)
138140
}
139141
}
142+
143+
override fun dispose() {
144+
cs.cancel()
145+
}
140146
}

src/main/kotlin/com/coder/gateway/views/steps/CoderLocateRemoteProjectStepView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
3131
import com.jetbrains.gateway.ssh.guessOs
3232
import kotlinx.coroutines.CoroutineScope
3333
import kotlinx.coroutines.Dispatchers
34+
import kotlinx.coroutines.cancel
3435
import kotlinx.coroutines.launch
3536
import kotlinx.coroutines.withContext
3637
import java.awt.Component
@@ -167,6 +168,7 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
167168
}
168169

169170
override fun dispose() {
171+
cs.cancel()
170172
}
171173

172174
companion object {

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.intellij.ui.dsl.gridLayout.VerticalAlign
2020
import com.intellij.util.ui.JBFont
2121
import kotlinx.coroutines.CoroutineScope
2222
import kotlinx.coroutines.Dispatchers
23+
import kotlinx.coroutines.cancel
2324
import kotlinx.coroutines.launch
2425
import kotlinx.coroutines.withContext
2526

@@ -81,7 +82,7 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
8182
}
8283

8384
override fun dispose() {
84-
85+
cs.cancel()
8586
}
8687

8788
companion object {

0 commit comments

Comments
 (0)