mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
IJPL-196231 Extract GlobalScope.launch in uiScope.kt
To get rid of the context duplication before we modify it. Reviewed in IJ-CR-168711 for 252 and release. (cherry picked from commit 02107333ea28d825af9550c9a70634e087414342) GitOrigin-RevId: 5ab9e46d71271e4dd854deaa5ac4e5fd01092acd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
270af06e6c
commit
c95451c5d7
@@ -58,8 +58,7 @@ fun <C : Component> C.launchOnceOnShow(
|
|||||||
ThreadingAssertions.assertEventDispatchThread()
|
ThreadingAssertions.assertEventDispatchThread()
|
||||||
val component = this
|
val component = this
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
return launchUnconfined(debugName) {
|
||||||
return GlobalScope.launch(Dispatchers.Unconfined + CoroutineName(debugName)) {
|
|
||||||
var started = false
|
var started = false
|
||||||
showingAsChannel(component) { channel ->
|
showingAsChannel(component) { channel ->
|
||||||
while (!started) {
|
while (!started) {
|
||||||
@@ -128,8 +127,7 @@ fun <C : Component> C.launchOnShow(
|
|||||||
ThreadingAssertions.assertEventDispatchThread()
|
ThreadingAssertions.assertEventDispatchThread()
|
||||||
val component = this
|
val component = this
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
return launchUnconfined(debugName) {
|
||||||
return GlobalScope.launch(Dispatchers.Unconfined + CoroutineName(debugName)) {
|
|
||||||
showingAsChannel(component) { channel ->
|
showingAsChannel(component) { channel ->
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
// Poor man's [distinctUntilChanged] + [collectLatest]
|
// Poor man's [distinctUntilChanged] + [collectLatest]
|
||||||
@@ -153,6 +151,17 @@ fun <C : Component> C.launchOnShow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launches the given task in the global scope without dispatching.
|
||||||
|
*/
|
||||||
|
private fun launchUnconfined(debugName: String, block: suspend CoroutineScope.() -> Unit): Job {
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
|
return GlobalScope.launch(
|
||||||
|
context = Dispatchers.Unconfined + CoroutineName(debugName),
|
||||||
|
block = block,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun showingAsChannel(component: Component, block: suspend (ReceiveChannel<Boolean>) -> Unit) {
|
private suspend fun showingAsChannel(component: Component, block: suspend (ReceiveChannel<Boolean>) -> Unit) {
|
||||||
val channel = Channel<Boolean>(capacity = Int.MAX_VALUE) // don't skip events
|
val channel = Channel<Boolean>(capacity = Int.MAX_VALUE) // don't skip events
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user