From 1678b637a6cec1176d795d96483e7caf562a506d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 13 Jan 2020 10:34:35 +0600 Subject: [PATCH] fillup readme with asFlow info and add one more test --- README.md | 26 ++++++++++++++ .../insanusmokrassar/krontab/utils/FailJob.kt | 8 +++++ .../krontab/utils/SchedulerFlow.kt | 35 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/commonTest/kotlin/com/insanusmokrassar/krontab/utils/FailJob.kt diff --git a/README.md b/README.md index ec1b0ba..1852a64 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ runtime of applications. | [ How to use: Including in project ](#including-in-project) | | [ How to use: Config from string ](#config-from-string) | | [ How to use: Config via builder (DSL preview) ](#config-via-builder) | +| [ How to use: KronScheduler as a Flow ](#KronScheduler-as-a-Flow) | ## How to use @@ -124,3 +125,28 @@ kronScheduler.doInfinity { ``` All of these examples will do the same things: print `Called` message every five seconds. + +### KronScheduler as a Flow + +Any `KronScheduler`can e converted to a `Flow + it.async { + var collected = 0 + flow.takeWhile { + collected < mustBeCollected + }.collect { + collected++ + } + collected + } + }.awaitAll() + + failJob.cancel() + + answers.forEach { + assertEquals(mustBeCollected, it) + } + } + } }