This commit is contained in:
InsanusMokrassar 2024-03-21 11:35:49 +00:00 committed by GitHub
commit 7774278b49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 2.3.0
* `doWhile` now will guarantee that it will not call `doOnce` more than once for time
## 2.2.9
* `Version`:

View File

@ -36,5 +36,5 @@ androidx_work_version=2.9.0
## Common
version=2.2.9
android_code_version=39
version=2.3.0
android_code_version=40

View File

@ -71,9 +71,18 @@ suspend inline fun <T> doOnceTz(
* Will execute [block] while it will return true as a result of its calculation
*/
suspend inline fun KronScheduler.doWhile(block: (DateTime) -> Boolean) {
var latest: DateTime? = null
do {
delay(1L)
} while (doOnce(block))
val result = doOnce {
if (latest != it) {
latest = it
block(it)
} else {
null
}
}
} while (result == null || result)
}
/**
* Will execute [block] while it will return true as a result of its calculation
@ -85,9 +94,18 @@ suspend inline fun KronScheduler.doWhileLocal(block: (DateTime) -> Boolean) = do
* Will execute [block] while it will return true as a result of its calculation
*/
suspend inline fun KronScheduler.doWhileTz(noinline block: suspend (DateTimeTz) -> Boolean) {
var latest: DateTimeTz? = null
do {
delay(1L)
} while (doOnceTz(block))
val result = doOnceTz {
if (latest != it) {
latest = it
block(it)
} else {
null
}
}
} while (result == null || result)
}
/**