Updated on 2026-08-14
This commit is contained in:
parent
e4c91780ed
commit
da8f4010e0
6 changed files with 175 additions and 38 deletions
|
|
@ -10,12 +10,16 @@ class PeriodicTask<T>(
|
|||
private val task: suspend () -> Result<T>,
|
||||
private val onSuccess: (T) -> Unit,
|
||||
private val onError: (Throwable) -> Unit,
|
||||
private val isDelayFirst: Boolean = false,
|
||||
) {
|
||||
|
||||
private var isActive: AtomicBoolean = AtomicBoolean(false)
|
||||
|
||||
suspend fun runTaskWithDelay() {
|
||||
isActive.set(true)
|
||||
if (isDelayFirst) {
|
||||
delay(delay)
|
||||
}
|
||||
while (isActive.get()) {
|
||||
task.invoke()
|
||||
.onSuccess {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue