Use app scoped CoroutineScope (#3403)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user