Skip to content

Commit

Permalink
remove for loops
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Mayer <[email protected]>
  • Loading branch information
JonasMayerDev committed Jan 29, 2024
1 parent fb07d2b commit fc33f40
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import java.util.concurrent.ExecutionException

fun WorkManager.isWorkScheduled(tag: String): Boolean {
val statuses: ListenableFuture<List<WorkInfo>> = this.getWorkInfosByTag(tag)
var running = false
var workInfoList: List<WorkInfo> = emptyList()

try {
Expand All @@ -40,17 +39,13 @@ fun WorkManager.isWorkScheduled(tag: String): Boolean {
Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e")
}

for (workInfo in workInfoList) {
val state = workInfo.state
running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED)
return workInfoList.any {
it.state == WorkInfo.State.RUNNING || it.state == WorkInfo.State.ENQUEUED
}

return running
}

fun WorkManager.isWorkRunning(tag: String): Boolean {
val statuses: ListenableFuture<List<WorkInfo>> = this.getWorkInfosByTag(tag)
var running = false
var workInfoList: List<WorkInfo> = emptyList()

try {
Expand All @@ -61,10 +56,7 @@ fun WorkManager.isWorkRunning(tag: String): Boolean {
Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e")
}

for (workInfo in workInfoList) {
val state = workInfo.state
running = running || state == WorkInfo.State.RUNNING
return workInfoList.any {
it.state == WorkInfo.State.RUNNING
}

return running
}

0 comments on commit fc33f40

Please sign in to comment.