louiscad
01/26/2018, 4:35 PMfun SomeReceiver.someFunction(parentJob: Job) {
someNonSuspendingCode()
setOnErrorListener { errorCode ->
parentJob.cancel(SomeException(errorCode))
}
}
I'm wondering if I should make it a suspend fun
so I can get the current job from the coroutineContext (currently available in the intrisics package) and remove this not so nice (IMHO) parentJob
parameter.
If I did, it'd look like this:
2️⃣
suspend fun SomeReceiver.someFunction() {
val currentJob = coroutineContext[Job]!!
someNonSuspendingCode()
setOnErrorListener { errorCode ->
currentJob.cancel(SomeException(errorCode))
}
}
elizarov
01/26/2018, 6:58 PM