diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/DownloadQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/DownloadQuery.kt index 038e8765..3cb75d79 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/DownloadQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/DownloadQuery.kt @@ -1,11 +1,16 @@ package suwayomi.tachidesk.graphql.queries +import kotlinx.coroutines.flow.first import suwayomi.tachidesk.graphql.types.DownloadStatus import suwayomi.tachidesk.manga.impl.download.DownloadManager +import suwayomi.tachidesk.server.JavalinSetup.future +import java.util.concurrent.CompletableFuture class DownloadQuery { - fun downloadStatus(): DownloadStatus { - return DownloadStatus(DownloadManager.status.value) + fun downloadStatus(): CompletableFuture { + return future { + DownloadStatus(DownloadManager.status.first()) + } } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt index 4d44c9f6..042054f7 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/download/DownloadManager.kt @@ -19,12 +19,11 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.sample -import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.serialization.Serializable import mu.KotlinLogging @@ -118,10 +117,8 @@ object DownloadManager { private val notifyFlow = MutableSharedFlow(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) val status = notifyFlow.sample(1.seconds) - .map { - getStatus() - } - .stateIn(scope, SharingStarted.Eagerly, getStatus()) + .onStart { emit(Unit) } + .map { getStatus() } init { scope.launch {