From cc60bfb97bf7dab9917e00357730f0d9c1397e8d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Oct 2019 16:34:59 +0600 Subject: [PATCH] fixes --- .../krontab/CronRegularExpression.kt | 18 ----------- .../insanusmokrassar/krontab/Executes.kt | 27 +++++++++++++++++ .../krontab/InternalCronRanges.kt | 7 +++++ .../insanusmokrassar/krontab/Scheduler.kt | 30 ------------------- 4 files changed, 34 insertions(+), 48 deletions(-) delete mode 100644 src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt create mode 100644 src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Executes.kt create mode 100644 src/commonMain/kotlin/com/github/insanusmokrassar/krontab/InternalCronRanges.kt delete mode 100644 src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt deleted file mode 100644 index 5cd8217..0000000 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.insanusmokrassar.krontab.utils - -internal val monthNumberRegex = Regex("(1[01]?)|(\\d)") -internal val dayOfMonthNumberRegex = Regex("(30?)|([012]?\\d)") -internal val hoursNumberRegex = Regex("(2[0123]?)|([01]?\\d)") -internal val minutesOrSecondsNumberRegex = Regex("[012345]?\\d") - -internal val monthRegex = Regex("[*]|((${monthNumberRegex.pattern})(,(${monthNumberRegex.pattern})){0,10})") -internal val dayOfMonthRegex = Regex("[*]|((${dayOfMonthNumberRegex.pattern})(,(${dayOfMonthNumberRegex.pattern})){0,29})") -internal val hoursRegex = Regex("[*]|((${hoursNumberRegex.pattern})(,(${hoursNumberRegex.pattern})){0,23})") -internal val minutesRegex = Regex("[*]|((${minutesOrSecondsNumberRegex.pattern})(,(${minutesOrSecondsNumberRegex.pattern})){0,59})") -internal val secondsRegex = minutesRegex - -internal val monthRange = 0 .. 11 -internal val dayOfMonthRange = 0 .. 30 -internal val hoursRange = 0 .. 23 -internal val minutesRange = 0 .. 59 -internal val secondsRange = minutesRange diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Executes.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Executes.kt new file mode 100644 index 0000000..902910c --- /dev/null +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Executes.kt @@ -0,0 +1,27 @@ +package com.github.insanusmokrassar.krontab + +suspend inline fun executeWith( + scheduler: CronDateTimeScheduler, + noinline block: suspend () -> Boolean +) = scheduler.doInLoop(block) + +suspend inline fun executeInfinity( + scheduleConfig: String, + noinline block: suspend () -> Unit +) = createCronDateTimeScheduler(scheduleConfig).doInLoop { + block() + true +} + +suspend inline fun executeWhile( + scheduleConfig: String, + noinline block: suspend () -> Boolean +) = createCronDateTimeScheduler(scheduleConfig).doInLoop(block) + +suspend inline fun executeOnce( + scheduleConfig: String, + noinline block: suspend () -> Unit +) = createCronDateTimeScheduler(scheduleConfig).doInLoop { + block() + false +} diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/InternalCronRanges.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/InternalCronRanges.kt new file mode 100644 index 0000000..c7c6b3b --- /dev/null +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/InternalCronRanges.kt @@ -0,0 +1,7 @@ +package com.github.insanusmokrassar.krontab + +internal val monthRange = 0 .. 11 +internal val dayOfMonthRange = 0 .. 30 +internal val hoursRange = 0 .. 23 +internal val minutesRange = 0 .. 59 +internal val secondsRange = minutesRange diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt deleted file mode 100644 index e044a00..0000000 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.insanusmokrassar.krontab - -suspend inline fun executeWith( - scheduler: CronDateTimeScheduler, - noinline block: suspend () -> Boolean -) = scheduler.doInLoop(block) - -suspend fun executeInfinity(scheduleConfig: String, block: suspend () -> Unit) { - val scheduler = createCronDateTimeScheduler(scheduleConfig) - - scheduler.doInLoop { - block() - true - } -} - -suspend fun executeWhile(scheduleConfig: String, block: suspend () -> Boolean) { - val scheduler = createCronDateTimeScheduler(scheduleConfig) - - scheduler.doInLoop(block) -} - -suspend fun executeOnce(scheduleConfig: String, block: suspend () -> Unit) { - val scheduler = createCronDateTimeScheduler(scheduleConfig) - - scheduler.doInLoop { - block() - false - } -}