diff --git a/src/commonMain/kotlin/dev/inmo/krontab/Executes.kt b/src/commonMain/kotlin/dev/inmo/krontab/Executes.kt index e15eebf..b35c7a2 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/Executes.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/Executes.kt @@ -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] diff --git a/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt b/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt index b54e308..d83fbcd 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt @@ -15,9 +15,8 @@ import kotlinx.coroutines.flow.* */ @FlowPreview fun KronSchedulerTz.asTzFlow(): Flow = channelFlow { - doWhile { + doInfinity { send(DateTime.nowLocal()) - isActive } } @@ -29,9 +28,8 @@ fun KronSchedulerTz.asTzFlow(): Flow = channelFlow { */ @FlowPreview fun KronScheduler.asFlow(): Flow = channelFlow { - doWhile { + doInfinity { send(DateTime.now()) - isActive } }