music: increase music load timeout

TagExtractor can take longer than 10 seconds to load, increase it to 60
seconds.
This commit is contained in:
Alexander Capehart 2024-01-28 21:37:20 -07:00
parent ced462e718
commit 6730766504
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 7 additions and 4 deletions

View file

@ -42,6 +42,7 @@ import org.oxycblt.auxio.music.metadata.Separators
import org.oxycblt.auxio.music.metadata.TagExtractor
import org.oxycblt.auxio.music.user.MutableUserLibrary
import org.oxycblt.auxio.music.user.UserLibrary
import org.oxycblt.auxio.util.DEFAULT_TIMEOUT
import org.oxycblt.auxio.util.forEachWithTimeout
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.logE
@ -481,7 +482,7 @@ constructor(
val rawSongs = LinkedList<RawSong>()
// Use a longer timeout so that dependent components can timeout and throw errors that
// provide more context than if we timed out here.
processedSongs.forEachWithTimeout(20000) {
processedSongs.forEachWithTimeout(DEFAULT_TIMEOUT * 2) {
rawSongs.add(it)
// Since discovery takes up the bulk of the music loading process, we switch to
// indicating a defined amount of loaded songs in comparison to the projected amount
@ -489,7 +490,7 @@ constructor(
emitIndexingProgress(IndexingProgress.Songs(rawSongs.size, query.projectedTotal))
}
withTimeout(10000) {
withTimeout(DEFAULT_TIMEOUT) {
mediaStoreJob.await()
tagJob.await()
}

View file

@ -152,6 +152,8 @@ private fun Fragment.launch(
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(state, block) }
}
const val DEFAULT_TIMEOUT = 60000L
/**
* Wraps [SendChannel.send] with a specified timeout.
*
@ -160,7 +162,7 @@ private fun Fragment.launch(
* @throws TimeoutException If the timeout is reached, provides context on what element
* specifically.
*/
suspend fun <E> SendChannel<E>.sendWithTimeout(element: E, timeout: Long = 10000) {
suspend fun <E> SendChannel<E>.sendWithTimeout(element: E, timeout: Long = DEFAULT_TIMEOUT) {
try {
withTimeout(timeout) { send(element) }
} catch (e: TimeoutCancellationException) {
@ -179,7 +181,7 @@ suspend fun <E> SendChannel<E>.sendWithTimeout(element: E, timeout: Long = 10000
* specifically.
*/
suspend fun <E> ReceiveChannel<E>.forEachWithTimeout(
timeout: Long = 10000,
timeout: Long = DEFAULT_TIMEOUT,
action: suspend (E) -> Unit
) {
var exhausted = false