update result checker in KronSchedulerWork

This commit is contained in:
InsanusMokrassar 2024-08-12 23:25:23 +06:00
parent 3845f6e0c5
commit 552ec14d66
2 changed files with 19 additions and 7 deletions

View File

@ -139,13 +139,14 @@ abstract class KronSchedulerWork(
}
throw e
}
result.outputData
if (result.isSuccess()) {
result.checkResults(
onFailure = {
if (prolongOnFailure) prolong()
},
onSuccess = {
if (prolongOnSuccess) prolong()
}
if (result.isFailure()) {
if (prolongOnFailure) prolong()
}
)
return result
}
}

View File

@ -8,3 +8,14 @@ internal fun ListenableWorker.Result.isSuccess() = this is ListenableWorker.Resu
@SuppressLint("RestrictedApi")
internal fun ListenableWorker.Result.isFailure() = this is ListenableWorker.Result.Failure
@SuppressLint("RestrictedApi")
internal inline fun ListenableWorker.Result.checkResults(
onFailure: () -> Unit,
onSuccess: () -> Unit
) {
when (this) {
is ListenableWorker.Result.Failure -> onFailure()
is ListenableWorker.Result.Success -> onSuccess()
}
}