now flows are using doInfinity

This commit is contained in:
InsanusMokrassar 2021-09-26 11:49:01 +06:00
parent 4dc65bf09a
commit d36e406b59
2 changed files with 6 additions and 6 deletions

View File

@ -3,6 +3,8 @@ package dev.inmo.krontab
import com.soywiz.klock.DateTime
import com.soywiz.klock.DateTimeTz
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlin.coroutines.coroutineContext
/**
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
@ -86,7 +88,7 @@ suspend inline fun doWhile(
*/
suspend inline fun KronScheduler.doInfinity(noinline block: suspend () -> Unit) = doWhile {
block()
true
coroutineContext.isActive
}
/**
@ -94,7 +96,7 @@ suspend inline fun KronScheduler.doInfinity(noinline block: suspend () -> Unit)
*/
suspend inline fun KronSchedulerTz.doInfinity(noinline block: suspend () -> Unit) = doWhile {
block()
true
coroutineContext.isActive
}
/**
* Will [buildSchedule] using [scheduleConfig] and call [doInfinity] with [block]

View File

@ -15,9 +15,8 @@ import kotlinx.coroutines.flow.*
*/
@FlowPreview
fun KronSchedulerTz.asTzFlow(): Flow<DateTimeTz> = channelFlow {
doWhile {
doInfinity {
send(DateTime.nowLocal())
isActive
}
}
@ -29,9 +28,8 @@ fun KronSchedulerTz.asTzFlow(): Flow<DateTimeTz> = channelFlow {
*/
@FlowPreview
fun KronScheduler.asFlow(): Flow<DateTime> = channelFlow {
doWhile {
doInfinity {
send(DateTime.now())
isActive
}
}