Hexa
05/13/2019, 1:05 PMval 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?
if(deleteJob!!.isCancelled){
//do something
}
// or
if(deleteJob == null){
//do something
}
r2vq
05/13/2019, 1:14 PMBooleans?
question?
if (deleteJob.isCancelled != false) {
// do something
}
That would handle both cases without risk of NPE right?dector
05/13/2019, 1:18 PMdeleteJob
will be always job for s.deleteItem(abc)
or null
.Hexa
05/13/2019, 7:27 PMif (deleteJob.isCancelled != false)
evaluate to true if the if deleteJob
times out and becomes null?r2vq
05/13/2019, 7:31 PMisCancelled
is true
or null
. I think what I meant to put was
if (deleteJob?.isCancelled != false) {
// do something
}
r2vq
05/13/2019, 7:32 PMdeleteJob
is null
as wellHexa
05/14/2019, 7:07 PM