mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: work around 'coroutineToIndicator' cancellation
GitOrigin-RevId: 91a873513decc6fec836654310e3e3f3b6b44e7a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1a1ba2c247
commit
a06ba79aee
@@ -124,7 +124,7 @@ abstract class AsyncChangesTree : ChangesTree {
|
||||
|
||||
private fun start() {
|
||||
scope.launch {
|
||||
_requests.collectLatest { request ->
|
||||
_requests.asyncCollectLatest(scope) { request ->
|
||||
handleRequest(request)
|
||||
}
|
||||
}
|
||||
@@ -287,3 +287,19 @@ abstract class TwoStepAsyncChangesTreeModel<T>(val scope: CoroutineScope) : Asyn
|
||||
return newJob.await()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [coroutineToIndicator]-friendly [collectLatest] implementation. Otherwise, indicator will never be cancelled.
|
||||
*/
|
||||
private suspend fun <T> Flow<T>.asyncCollectLatest(scope: CoroutineScope, action: suspend (value: T) -> Unit) {
|
||||
var lastJob: Job? = null
|
||||
collect { request ->
|
||||
lastJob?.let {
|
||||
it.cancel()
|
||||
it.join()
|
||||
}
|
||||
lastJob = scope.launch {
|
||||
action(request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user