From c3ed1d024cbf8c04b4c5c18527ef94621a013e6a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 3 Jun 2021 12:16:39 +0600 Subject: [PATCH] fix tests --- CHANGELOG.md | 4 +--- .../kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 272ce4f..ff0f03e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,7 @@ ## 0.6.1 * Versions - * `Klock`: `2.1.0` -> `2.1.2 - -` + * `Klock`: `2.1.0` -> `2.1.2` ## 0.6.0 diff --git a/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt b/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt index 81738f4..1382d86 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt @@ -15,9 +15,16 @@ import kotlinx.coroutines.flow.* */ @FlowPreview fun KronScheduler.asTzFlow(): Flow = channelFlow { + var previousTime = DateTime.nowLocal() while (isActive) { - val now = DateTime.now().local + val now = DateTime.nowLocal() val nextTime = next(now) ?: break + if (previousTime == nextTime) { + delay(1L) // skip 1ms + continue + } else { + previousTime = nextTime + } val sleepDelay = (nextTime - DateTime.now().local).millisecondsLong delay(sleepDelay) send(nextTime) @@ -48,4 +55,4 @@ class SchedulerFlow( collector.emit(nextTime) } } -} \ No newline at end of file +}