I guess it would have been nice to have a `getComp...
# coroutines
d
I guess it would have been nice to have a
getCompletedOrNull()
that returns a null instead of throwing... so currently the only way is to
runCatching { deferred.getCompleted() }.getOrElse { defaultValue }
?
a
You can check
isCompleted
instead
if(deferred.isCompleted()) getCompleted() else defaultValue
c
So here's your
poll
method:
fun <T: Any> Deferred<T>.poll() = if (isCompleted) getCompleted() else null