Show page loading progress
parent
9588ac8cbd
commit
889eea9c89
@ -1,22 +0,0 @@
|
||||
package org.koitharu.kotatsu.utils
|
||||
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
||||
class DeferredStateFlow<R, S>(
|
||||
private val stateFlow: StateFlow<S>,
|
||||
private val deferred: Deferred<R>,
|
||||
) : StateFlow<S> by stateFlow, Deferred<R> by deferred {
|
||||
|
||||
suspend fun collectAndAwait(): R {
|
||||
return coroutineScope {
|
||||
val collectJob = launchIn(this)
|
||||
val result = await()
|
||||
collectJob.cancelAndJoin()
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package org.koitharu.kotatsu.utils
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
||||
class JobStateFlow<S>(
|
||||
private val stateFlow: StateFlow<S>,
|
||||
private val job: Job,
|
||||
) : StateFlow<S> by stateFlow, Job by job {
|
||||
|
||||
suspend fun collectAndJoin(): Unit {
|
||||
coroutineScope {
|
||||
val collectJob = launchIn(this)
|
||||
join()
|
||||
collectJob.cancelAndJoin()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package org.koitharu.kotatsu.utils.progress
|
||||
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
class ProgressDeferred<T, P>(
|
||||
private val deferred: Deferred<T>,
|
||||
private val progress: StateFlow<P>,
|
||||
) : Deferred<T> by deferred {
|
||||
|
||||
val progressValue: P
|
||||
get() = progress.value
|
||||
|
||||
fun progressAsFlow(): Flow<P> = progress
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package org.koitharu.kotatsu.utils.progress
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
class ProgressJob<P>(
|
||||
private val job: Job,
|
||||
private val progress: StateFlow<P>,
|
||||
) : Job by job {
|
||||
|
||||
val progressValue: P
|
||||
get() = progress.value
|
||||
|
||||
fun progressAsFlow(): Flow<P> = progress
|
||||
}
|
||||
Loading…
Reference in New Issue