Use app scoped CoroutineScope (#3403)

This commit is contained in:
AntsyLich
2026-06-12 17:14:29 +06:00
committed by GitHub
parent 63a71fa447
commit 509eee5dfb
17 changed files with 91 additions and 80 deletions
@@ -10,6 +10,7 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.receiveAsFlow
@@ -17,15 +18,14 @@ import kotlinx.coroutines.flow.shareIn
class StorageManager(
private val context: Context,
scope: CoroutineScope,
storagePreferences: StoragePreferences,
) {
private val scope = CoroutineScope(Dispatchers.IO)
private var baseDir: UniFile? = getBaseDir(storagePreferences.baseStorageDirectory.get())
private val _changes: Channel<Unit> = Channel(Channel.UNLIMITED)
val changes = _changes.receiveAsFlow()
.flowOn(Dispatchers.IO)
.shareIn(scope, SharingStarted.Lazily, 1)
init {
@@ -43,6 +43,7 @@ class StorageManager(
}
_changes.send(Unit)
}
.flowOn(Dispatchers.IO)
.launchIn(scope)
}