Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send every download status change to the subscriber #684

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<DownloadStatus> {
return future {
DownloadStatus(DownloadManager.status.first())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,10 +117,8 @@ object DownloadManager {
private val notifyFlow = MutableSharedFlow<Unit>(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 {
Expand Down