chore: coroutine SupervisorJob

This commit is contained in:
hstyi
2025-04-01 15:57:08 +08:00
committed by hstyi
parent d90fb9aa35
commit 1ab0d26bab
6 changed files with 8 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import app.termora.actions.DataProviders
import app.termora.terminal.* import app.termora.terminal.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.swing.Swing import kotlinx.coroutines.swing.Swing
import java.beans.PropertyChangeEvent import java.beans.PropertyChangeEvent
@@ -19,7 +20,7 @@ abstract class HostTerminalTab(
val Host = DataKey(app.termora.Host::class) val Host = DataKey(app.termora.Host::class)
} }
protected val coroutineScope by lazy { CoroutineScope(Dispatchers.Swing) } protected val coroutineScope by lazy { CoroutineScope(SupervisorJob() + Dispatchers.Swing) }
protected val terminalModel get() = terminal.getTerminalModel() protected val terminalModel get() = terminal.getTerminalModel()
protected var unread = false protected var unread = false
set(value) { set(value) {

View File

@@ -89,7 +89,7 @@ class TerminalPanelFactory : Disposable {
} }
} }
private val coroutineScope = CoroutineScope(Dispatchers.IO) private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
init { init {
coroutineScope.launch { coroutineScope.launch {

View File

@@ -43,7 +43,7 @@ class SSHCopyIdDialog(
terminalPanelFactory.createTerminalPanel(terminal, PtyConnectorDelegate()) terminalPanelFactory.createTerminalPanel(terminal, PtyConnectorDelegate())
.apply { enableFloatingToolbar = false } .apply { enableFloatingToolbar = false }
} }
private val coroutineScope = CoroutineScope(Job() + Dispatchers.IO) private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
init { init {
size = Dimension(UIManager.getInt("Dialog.width") - 100, UIManager.getInt("Dialog.height") - 100) size = Dimension(UIManager.getInt("Dialog.width") - 100, UIManager.getInt("Dialog.height") - 100)

View File

@@ -93,7 +93,7 @@ class TerminalBlink(terminal: Terminal) : Disposable {
} }
} }
val coroutineScope by lazy { CoroutineScope(Dispatchers.IO) } val coroutineScope by lazy { CoroutineScope(SupervisorJob() + Dispatchers.IO) }
/** /**
* 返回 true 表示可以显示某些内容 [TextStyle.blink] * 返回 true 表示可以显示某些内容 [TextStyle.blink]

View File

@@ -11,7 +11,7 @@ abstract class AutoRefreshPanel : JPanel(), Disposable {
private val log = LoggerFactory.getLogger(AutoRefreshPanel::class.java) private val log = LoggerFactory.getLogger(AutoRefreshPanel::class.java)
} }
protected val coroutineScope = CoroutineScope(Dispatchers.IO) protected val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
protected abstract suspend fun refresh(isFirst: Boolean) protected abstract suspend fun refresh(isFirst: Boolean)

View File

@@ -110,7 +110,8 @@ class TerminalLoggerDataListener(private val terminal: Terminal) : DataListener
action.removePropertyChangeListener(terminalLoggerActionPropertyChangeListener) action.removePropertyChangeListener(terminalLoggerActionPropertyChangeListener)
action.addPropertyChangeListener(terminalLoggerActionPropertyChangeListener) action.addPropertyChangeListener(terminalLoggerActionPropertyChangeListener)
val coroutineScope = this.coroutineScope ?: CoroutineScope(Dispatchers.IO).apply { coroutineScope = this } val coroutineScope =
this.coroutineScope ?: CoroutineScope(SupervisorJob() + Dispatchers.IO).apply { coroutineScope = this }
val channel = this.channel ?: Channel<String>(Channel.UNLIMITED).apply { channel = this } val channel = this.channel ?: Channel<String>(Channel.UNLIMITED).apply { channel = this }
coroutineScope.launch { coroutineScope.launch {