From d36e406b5995e50c49c2b7c5430e01fc9387f239 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 26 Sep 2021 11:49:01 +0600 Subject: [PATCH] now flows are using doInfinity --- src/commonMain/kotlin/dev/inmo/krontab/Executes.kt | 6 ++++-- .../kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) 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 } }