if I have a coroutine like this: ...
# coroutines
h
if I have a coroutine like this:
Copy code
val  deleteJob = runBlocking {
                    withTimeoutOrNull(10000L) {
                        launch(<http://Dispatchers.IO|Dispatchers.IO>) { s.deleteItem(xyz) }
                        launch(<http://Dispatchers.IO|Dispatchers.IO>) { s.deleteItem(abc) }
                    }
                }
which one of these is the best way to handle a couroutine that timedout?
Copy code
if(deleteJob!!.isCancelled){
                    //do something
                }
// or
Copy code
if(deleteJob == null){
                    //do something
                }
r
Is this a Coroutine specific question or just a handling of
Booleans?
question?
Copy code
if (deleteJob.isCancelled != false) {
    // do something
}
That would handle both cases without risk of NPE right?
d
I suppose that
deleteJob
will be always job for
s.deleteItem(abc)
or
null
.
h
thanks @r2vq, and @dector , just to clarify, will
if (deleteJob.isCancelled != false)
evaluate to true if the if
deleteJob
times out and becomes null?
r
It’ll evaluate to false if
isCancelled
is
true
or
null
. I think what I meant to put was
Copy code
if (deleteJob?.isCancelled != false) {
    // do something
}
That will evaluate to false if
deleteJob
is
null
as well
h
cool will try that thanks @r2vq