Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knowing all status of a Job with Kotlin coroutines

Is it possible to know all the status of a coroutine Job ?

I find this function extension but I can't access to all the status of a Job :

fun Job.status(): String = when {
    isCancelled -> "cancelled"
    isActive -> "Active"
    isCompleted -> "Complete"
    else -> "Nothing"
}

There is no isNew, isCancelling or isWaitingForChildren functions with the Job classe. Why ?

enter image description here

like image 924
Jéwôm' Avatar asked Feb 11 '20 14:02

Jéwôm'


1 Answers

Thanks to Drawn Roccoon I found the solution :

fun Job.status(): String = when {
    isActive -> "Active/Completing"
    isCompleted && isCancelled -> "Cancelled"
    isCancelled -> "Cancelling"
    isCompleted -> "Completed"
    else -> "New"
}

enter image description here

More information in this link : https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/

like image 176
Jéwôm' Avatar answered Nov 01 '22 10:11

Jéwôm'