mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2025-12-05 04:25:48 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 211b57cdf6 | |||
| 6b4bc42f3d | |||
| c406f883d2 | |||
| 93b56c0861 | |||
| 801c27c7f8 | |||
| cbfbdc1b33 | |||
| 715d414f51 | |||
| 2ecd8c4292 | |||
| 1be8d947f7 | |||
| f66c1c2477 | |||
| 69cf7afd4e | |||
| 92df91edd3 | |||
| f7a388f438 | |||
| 9a10c7eb87 | |||
| d67be582af | |||
| 171bb687ea | |||
| 7807d10121 |
31
CHANGELOG.md
31
CHANGELOG.md
@@ -1,5 +1,36 @@
|
||||
# Changelog
|
||||
|
||||
## 2.2.1
|
||||
|
||||
* Potential fix of [#65](https://github.com/InsanusMokrassar/krontab/issues/65)
|
||||
* Versions
|
||||
* `Kotlin`: `1.9.20-Beta`
|
||||
* `Klock`: `4.0.10`
|
||||
* `Serialization`: `1.6.0`
|
||||
|
||||
## 2.2.0
|
||||
|
||||
* Versions
|
||||
* `Kotlin`: `1.9.0`
|
||||
* `Coroutines`: `1.7.3`
|
||||
* `Klock`: `4.0.9`
|
||||
|
||||
## 2.1.2
|
||||
|
||||
* Versions
|
||||
* `Coroutines`: `1.7.2`
|
||||
* All callbacks for standard extensions like `doInfinity` now fully inline
|
||||
|
||||
## 2.1.1
|
||||
|
||||
* `asFlowWithoutDelays` and `asTzFlowWithoutDelays` will have nullable `since` parameters with default to `null`
|
||||
to avoid any inconsistency of `Flow` idiom.
|
||||
<details>
|
||||
<summary>About the reason of changes</summary>
|
||||
Cold flows should not contain some state by default. So, it was not right to save some `DateTime`/`DateTimeTz`
|
||||
by default. Now it will not use some external state unless developers will set it manually
|
||||
</details>
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* Versions
|
||||
|
||||
@@ -97,7 +97,7 @@ kotlin {
|
||||
implementation kotlin('test-js')
|
||||
}
|
||||
}
|
||||
androidTest {
|
||||
androidUnitTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ android.useAndroidX=true
|
||||
android.enableJetifier=false
|
||||
|
||||
|
||||
kotlin_version=1.8.22
|
||||
kotlin_coroutines_version=1.6.4
|
||||
kotlin_serialization_version=1.5.1
|
||||
kotlin_version=1.9.20-Beta
|
||||
kotlin_coroutines_version=1.7.3
|
||||
kotlin_serialization_version=1.6.0
|
||||
|
||||
dokka_version=1.8.20
|
||||
dokka_version=1.9.0
|
||||
|
||||
klockVersion=4.0.3
|
||||
klockVersion=4.0.10
|
||||
|
||||
## Github reease
|
||||
|
||||
@@ -36,5 +36,5 @@ androidx_work_version=2.8.1
|
||||
|
||||
## Common
|
||||
|
||||
version=2.1.0
|
||||
android_code_version=27
|
||||
version=2.2.1
|
||||
android_code_version=31
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
|
||||
|
||||
@@ -14,7 +14,7 @@ import kotlin.coroutines.coroutineContext
|
||||
*
|
||||
* WARNING!!! In case if [KronScheduler.next] of [this] instance will return null, [block] will be called immediately
|
||||
*/
|
||||
suspend inline fun <T> KronScheduler.doOnce(noinline block: suspend (DateTime) -> T): T {
|
||||
suspend inline fun <T> KronScheduler.doOnce(block: (DateTime) -> T): T {
|
||||
val time = nextOrNow().also {
|
||||
delay((it - DateTime.now()).millisecondsLong)
|
||||
}
|
||||
@@ -29,7 +29,7 @@ suspend inline fun <T> KronScheduler.doOnce(noinline block: suspend (DateTime) -
|
||||
* WARNING!!! In case if [KronScheduler.next] of [this] instance will return null, [block] will be called immediately
|
||||
*/
|
||||
@Deprecated("Replaceable", ReplaceWith("doOnce", "dev.inmo.krontab.doOnce"))
|
||||
suspend inline fun <T> KronScheduler.doOnceLocal(noinline block: suspend (DateTime) -> T): T = doOnce(block)
|
||||
suspend inline fun <T> KronScheduler.doOnceLocal(block: (DateTime) -> T): T = doOnce(block)
|
||||
|
||||
/**
|
||||
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
|
||||
@@ -53,7 +53,7 @@ suspend inline fun <T> KronScheduler.doOnceTz(noinline block: suspend (DateTimeT
|
||||
*/
|
||||
suspend inline fun <T> doOnce(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend (DateTime) -> T
|
||||
block: (DateTime) -> T
|
||||
) = buildSchedule(scheduleConfig).doOnce(block)
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ suspend inline fun <T> doOnceTz(
|
||||
/**
|
||||
* Will execute [block] while it will return true as a result of its calculation
|
||||
*/
|
||||
suspend inline fun KronScheduler.doWhile(noinline block: suspend (DateTime) -> Boolean) {
|
||||
suspend inline fun KronScheduler.doWhile(block: (DateTime) -> Boolean) {
|
||||
do {
|
||||
delay(1L)
|
||||
} while (doOnce(block))
|
||||
@@ -78,7 +78,7 @@ suspend inline fun KronScheduler.doWhile(noinline block: suspend (DateTime) -> B
|
||||
* Will execute [block] while it will return true as a result of its calculation
|
||||
*/
|
||||
@Deprecated("Replaceable", ReplaceWith("doWhile", "dev.inmo.krontab.doWhile"))
|
||||
suspend inline fun KronScheduler.doWhileLocal(noinline block: suspend (DateTime) -> Boolean) = doWhile(block)
|
||||
suspend inline fun KronScheduler.doWhileLocal(block: (DateTime) -> Boolean) = doWhile(block)
|
||||
|
||||
/**
|
||||
* Will execute [block] while it will return true as a result of its calculation
|
||||
@@ -96,7 +96,7 @@ suspend inline fun KronScheduler.doWhileTz(noinline block: suspend (DateTimeTz)
|
||||
*/
|
||||
suspend inline fun doWhile(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend (DateTime) -> Boolean
|
||||
block: (DateTime) -> Boolean
|
||||
) = buildSchedule(scheduleConfig).doWhile(block)
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ suspend inline fun doWhile(
|
||||
@Deprecated("Replaceable", ReplaceWith("doWhile", "dev.inmo.krontab.doWhile"))
|
||||
suspend inline fun doWhileLocal(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend (DateTime) -> Boolean
|
||||
block: (DateTime) -> Boolean
|
||||
) = doWhile(scheduleConfig, block)
|
||||
|
||||
/**
|
||||
@@ -124,7 +124,7 @@ suspend inline fun doWhileTz(
|
||||
/**
|
||||
* Will execute [block] without any checking of result
|
||||
*/
|
||||
suspend inline fun KronScheduler.doInfinity(noinline block: suspend (DateTime) -> Unit) = doWhile {
|
||||
suspend inline fun KronScheduler.doInfinity(block: (DateTime) -> Unit) = doWhile {
|
||||
block(it)
|
||||
coroutineContext.isActive
|
||||
}
|
||||
@@ -132,7 +132,7 @@ suspend inline fun KronScheduler.doInfinity(noinline block: suspend (DateTime) -
|
||||
* Will execute [block] without any checking of result
|
||||
*/
|
||||
@Deprecated("Replaceable", ReplaceWith("doInfinity", "dev.inmo.krontab.doInfinity"))
|
||||
suspend inline fun KronScheduler.doInfinityLocal(noinline block: suspend (DateTime) -> Unit) = doInfinity(block)
|
||||
suspend inline fun KronScheduler.doInfinityLocal(block: (DateTime) -> Unit) = doInfinity(block)
|
||||
|
||||
/**
|
||||
* Will execute [block] without any checking of result
|
||||
@@ -149,7 +149,7 @@ suspend inline fun KronScheduler.doInfinityTz(noinline block: suspend (DateTimeT
|
||||
*/
|
||||
suspend inline fun doInfinity(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend (DateTime) -> Unit
|
||||
block: (DateTime) -> Unit
|
||||
) = buildSchedule(scheduleConfig).doInfinity(block)
|
||||
|
||||
/**
|
||||
@@ -160,7 +160,7 @@ suspend inline fun doInfinity(
|
||||
@Deprecated("Replaceable", ReplaceWith("doInfinity", "dev.inmo.krontab.doInfinity"))
|
||||
suspend inline fun doInfinityLocal(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend (DateTime) -> Unit
|
||||
block: (DateTime) -> Unit
|
||||
) = doInfinity(scheduleConfig, block)
|
||||
|
||||
/**
|
||||
@@ -108,13 +108,19 @@ internal fun NearDateTimeCalculatorDays(
|
||||
} else {
|
||||
dateTime
|
||||
})
|
||||
dateTime.copy(
|
||||
val newDateTime = dateTime.copy(
|
||||
dayOfMonth = min(dateTime.month.days(dateTime.year), newOne.toInt() + 1), // index1
|
||||
hour = 0,
|
||||
minute = 0,
|
||||
second = 0,
|
||||
milliseconds = 0
|
||||
)
|
||||
// If day of month has not been changed, use old dateTime due to no changes required
|
||||
if (newDateTime.dayOfMonth == dateTime.dayOfMonth) {
|
||||
dateTime
|
||||
} else {
|
||||
newDateTime
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -18,10 +18,11 @@ import kotlinx.coroutines.isActive
|
||||
* Will emit all the [KronScheduler.next] as soon as possible. In case [KronScheduler.next] return null, flow will
|
||||
* be completed
|
||||
*
|
||||
* @param since Will be used as the first parameter for [KronScheduler.next] fun
|
||||
* @param since Will be used as the first parameter for [KronScheduler.next] fun. If passed null, `flow`
|
||||
* will always start since the moment of collecting start
|
||||
*/
|
||||
fun KronScheduler.asTzFlowWithoutDelays(since: DateTimeTz = DateTime.nowLocal()): Flow<DateTimeTz> = flow {
|
||||
var previous = since
|
||||
fun KronScheduler.asTzFlowWithoutDelays(since: DateTimeTz? = null): Flow<DateTimeTz> = flow {
|
||||
var previous = since ?: DateTime.nowLocal()
|
||||
while (currentCoroutineContext().isActive) {
|
||||
val next = next(previous) ?: break
|
||||
emit(next)
|
||||
@@ -57,10 +58,11 @@ fun KronScheduler.asTzFlow(): Flow<DateTimeTz> = asTzFlowWithDelays()
|
||||
* Will emit all the [KronScheduler.next] as soon as possible. In case [KronScheduler.next] return null, flow will
|
||||
* be completed
|
||||
*
|
||||
* @param since Will be used as the first parameter for [KronScheduler.next] fun
|
||||
* @param since Will be used as the first parameter for [KronScheduler.next] fun. If passed null, `flow`
|
||||
* will always start since the moment of collecting start
|
||||
*/
|
||||
fun KronScheduler.asFlowWithoutDelays(since: DateTime = DateTime.now()): Flow<DateTime> = flow {
|
||||
var previous = since
|
||||
fun KronScheduler.asFlowWithoutDelays(since: DateTime? = null): Flow<DateTime> = flow {
|
||||
var previous = since ?: DateTime.now()
|
||||
while (currentCoroutineContext().isActive) {
|
||||
val next = next(previous) ?: break
|
||||
emit(next)
|
||||
Reference in New Issue
Block a user