mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-26 03:58:50 +00:00
now flows are using doInfinity
This commit is contained in:
parent
4dc65bf09a
commit
d36e406b59
@ -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]
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user