Add support for IntelliJ cron tab feature

This commit is contained in:
Michael Rittmeister 2024-06-16 16:33:55 +02:00
parent f90d8d03d9
commit e5b33ae9b0
No known key found for this signature in database
GPG Key ID: 20ED60DB80559DEB
3 changed files with 19 additions and 9 deletions

View File

@ -7,7 +7,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlin.coroutines.coroutineContext import kotlin.coroutines.coroutineContext
/** /**
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation. * Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
* *
@ -53,7 +52,7 @@ suspend inline fun <T> KronScheduler.doOnceTz(noinline block: suspend (DateTimeT
* @see buildSchedule * @see buildSchedule
*/ */
suspend inline fun <T> doOnce( suspend inline fun <T> doOnce(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
block: (DateTime) -> T block: (DateTime) -> T
) = buildSchedule(scheduleConfig).doOnce(block) ) = buildSchedule(scheduleConfig).doOnce(block)
@ -62,7 +61,7 @@ suspend inline fun <T> doOnce(
* @see buildSchedule * @see buildSchedule
*/ */
suspend inline fun <T> doOnceTz( suspend inline fun <T> doOnceTz(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
noinline block: suspend (DateTimeTz) -> T noinline block: suspend (DateTimeTz) -> T
) = buildSchedule(scheduleConfig).doOnceTz(block) ) = buildSchedule(scheduleConfig).doOnceTz(block)
@ -114,7 +113,7 @@ suspend inline fun KronScheduler.doWhileTz(noinline block: suspend (DateTimeTz)
* @see buildSchedule * @see buildSchedule
*/ */
suspend inline fun doWhile( suspend inline fun doWhile(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
block: (DateTime) -> Boolean block: (DateTime) -> Boolean
) = buildSchedule(scheduleConfig).doWhile(block) ) = buildSchedule(scheduleConfig).doWhile(block)
@ -125,7 +124,7 @@ suspend inline fun doWhile(
*/ */
@Deprecated("Replaceable", ReplaceWith("doWhile", "dev.inmo.krontab.doWhile")) @Deprecated("Replaceable", ReplaceWith("doWhile", "dev.inmo.krontab.doWhile"))
suspend inline fun doWhileLocal( suspend inline fun doWhileLocal(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
block: (DateTime) -> Boolean block: (DateTime) -> Boolean
) = doWhile(scheduleConfig, block) ) = doWhile(scheduleConfig, block)
@ -135,7 +134,7 @@ suspend inline fun doWhileLocal(
* @see buildSchedule * @see buildSchedule
*/ */
suspend inline fun doWhileTz( suspend inline fun doWhileTz(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
noinline block: suspend (DateTimeTz) -> Boolean noinline block: suspend (DateTimeTz) -> Boolean
) = buildSchedule(scheduleConfig).doWhileTz(block) ) = buildSchedule(scheduleConfig).doWhileTz(block)
@ -167,7 +166,7 @@ suspend inline fun KronScheduler.doInfinityTz(noinline block: suspend (DateTimeT
* @see buildSchedule * @see buildSchedule
*/ */
suspend inline fun doInfinity( suspend inline fun doInfinity(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
block: (DateTime) -> Unit block: (DateTime) -> Unit
) = buildSchedule(scheduleConfig).doInfinity(block) ) = buildSchedule(scheduleConfig).doInfinity(block)
@ -178,7 +177,7 @@ suspend inline fun doInfinity(
*/ */
@Deprecated("Replaceable", ReplaceWith("doInfinity", "dev.inmo.krontab.doInfinity")) @Deprecated("Replaceable", ReplaceWith("doInfinity", "dev.inmo.krontab.doInfinity"))
suspend inline fun doInfinityLocal( suspend inline fun doInfinityLocal(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
block: (DateTime) -> Unit block: (DateTime) -> Unit
) = doInfinity(scheduleConfig, block) ) = doInfinity(scheduleConfig, block)
@ -188,6 +187,6 @@ suspend inline fun doInfinityLocal(
* @see buildSchedule * @see buildSchedule
*/ */
suspend inline fun doInfinityTz( suspend inline fun doInfinityTz(
scheduleConfig: String, @Language("CronExp") scheduleConfig: String,
noinline block: suspend (DateTimeTz) -> Unit noinline block: suspend (DateTimeTz) -> Unit
) = buildSchedule(scheduleConfig).doInfinityTz(block) ) = buildSchedule(scheduleConfig).doInfinityTz(block)

View File

@ -0,0 +1,6 @@
package dev.inmo.krontab
import kotlin.OptionalExpectation
@OptionalExpectation
internal expect annotation class Language(val value: String, val prefix: String = "", val suffix: String = "")

View File

@ -0,0 +1,5 @@
package dev.inmo.krontab
import org.intellij.lang.annotations.Language
actual typealias Language = Language