Skip to content

Commit 12db6c1

Browse files
committed
Optimize library loading by using IO dispatcher for coroutine tasks
This may improve app startup time by not blocking the coroutines threads.
1 parent 1e8350e commit 12db6c1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app/desktop/src/main/kotlin/AniDesktop.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import kotlinx.coroutines.flow.firstOrNull
4747
import kotlinx.coroutines.joinAll
4848
import kotlinx.coroutines.launch
4949
import kotlinx.coroutines.runBlocking
50+
import kotlinx.coroutines.withContext
5051
import me.him188.ani.app.data.models.preference.DarkMode
5152
import me.him188.ani.app.data.repository.SavedWindowState
5253
import me.him188.ani.app.data.repository.WindowStateRepository
@@ -287,7 +288,7 @@ object AniDesktop {
287288
}
288289
}
289290

290-
val loadAnitorrentJob = coroutineScope.launch {
291+
val loadAnitorrentJob = coroutineScope.launch(Dispatchers.IO) {
291292
try {
292293
AnitorrentLibraryLoader.loadLibraries()
293294
} catch (e: Throwable) {
@@ -324,7 +325,9 @@ object AniDesktop {
324325

325326
// 预先加载 VLC, https://github.com/open-ani/ani/issues/618
326327
kotlin.runCatching {
327-
VlcMediampPlayer.prepareLibraries()
328+
withContext(Dispatchers.IO) {
329+
VlcMediampPlayer.prepareLibraries()
330+
}
328331
}.onFailure {
329332
logger.error(it) { "Failed to prepare VLC" }
330333
}

0 commit comments

Comments
 (0)