all: fix unscoped coroutines
This commit is contained in:
@@ -21,6 +21,7 @@ package org.oxycblt.auxio.detail
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -418,7 +419,7 @@ constructor(
|
||||
val playlist = currentPlaylist.value ?: return
|
||||
val editedPlaylist = editedPlaylist.value ?: return
|
||||
L.d("Committing playlist edits")
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
musicRepository.rewritePlaylist(playlist, editedPlaylist)
|
||||
// TODO: The user could probably press some kind of button if they were fast enough.
|
||||
// Think of a better way to handle this state.
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.oxycblt.auxio.playback
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -187,7 +188,7 @@ constructor(
|
||||
// Replace the previous position co-routine with a new one that uses the new
|
||||
// state information.
|
||||
lastPositionJob?.cancel()
|
||||
lastPositionJob = viewModelScope.launch {
|
||||
lastPositionJob = viewModelScope.launch(Dispatchers.Default) {
|
||||
while (true) {
|
||||
positionDs.value = progression.calculateElapsedPositionMs().msToDs()
|
||||
// Wait a deci-second for the next position tick.
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.oxycblt.auxio.search
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -100,7 +101,7 @@ constructor(
|
||||
|
||||
// Searching is time-consuming, so do it in the background.
|
||||
L.d("Searching music library for $query")
|
||||
currentSearchJob = viewModelScope.launch {
|
||||
currentSearchJob = viewModelScope.launch(Dispatchers.Default) {
|
||||
searchResults.value = searchImpl(library, query).also { yield() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user