KotlinConf 2019: Coroutines! Gotta catch 'em all! by Florina Muntenescu & Manuel Vivo
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about coroutine contexts, scopes, async/await behavior, and unexpected JobCancellationException crashes.
Recommended by 3 people across 4 different months, 2020 to 2021.
What it is
A KotlinConf 2019 talk by two Google Android developer advocates on handling errors and cancellation in Kotlin coroutines. It covers structured concurrency, choosing scopes, and how launch versus async change error propagation and handling.
What people said
Strong rec USMAN osman · 2020-09 · Stack Overflow · on “Kotlin difference between CoroutineScope and withContext”
Technically both are same but when it comes to use case both are different and has big impact on the different use cases so be careful while using them Coroutine Scope: CoroutineScope is a starting Point of Coroutine. CoroutineScope can have more than one coroutine within itself, which makes coroutine hierarchy. Lets think, Parent has more than one children. Think CoroutineScope is a parent and this parent can have more than one child which are also coroutines. These childrens are known as job private val coroutineScope = CoroutineScope() coroutineScope(IO).launch{ val childOne = launch(Main){} val childTwo = launch(Main){} } see that childOne and childTwo? why we need these? because we can'
Recommends ferini · 2020-03 · Stack Overflow · on “What's the purpose of combining coroutine contexts in Kotlin?”
I think you are confusing CoroutineContext and CoroutineDispatcher (possibly also CoroutineScope ). Dispatcher is only one kind of Context. Others can be eg. Job , CoroutineName , CoroutineExceptionHandler . You can combine multiple of these - eg. to set dispatcher and error handler - but only have one of each type. It does not make sense to combine multiple dispatchers, the only the last one will be applied. I found the talk Coroutines! Gotta catch 'em all! by Florina Muntenescu & Manuel Vivo [this video] from KotlinConf 2019 explaining some of this quite well.
Recommends ParadiseHell · 2020-05 · Stack Overflow · on “How to fix Kotlin JobCancellationException?”
Finally, I found what causes the Exception and the issue address is flowing: kotlin.coroutines.channels.awaitClose: JobCancellationException [LINK] Actually, awaitClose will not throw the JobCancellationException , because awaitClose is a cancellable suspended function. The offer method will throw JobCancellationException if the Job was canceled because offer is not a cancellable suspended function. By the way, callbackFlow is an experimental API, so it may cause some bug, so when we use it, we need to be careful. Because it will not always ignore JobCancellationException when Job was canceled, and I don't think it's friendly to developers. Now I have found 2 situations that will cause JobCa
Recommends USMAN osman · 2021-06 · Stack Overflow · on “How do I wait for the first function to finish before executing the second function in Kotlin?”
@EmanuelMoecklin the usecase was, he wanted something that runs sequentially even though with the delays and its not only about suspending function. what ``async`` does it makes the request either it succeeds or faileds and what ``await`` does it waits for the result for further process. same goes with the fun2. async/await are not only for suspending function but rather it helps to make code sequential or you can make it parallel as well. further i would refer this kotlinconf: [this video]
Cites ParadiseHell · 2020-05 · Stack Overflow · on “How to fix Kotlin JobCancellationException?”
I got a crash because of Kotlin JobCancellationException. The following is the detail about the crash : kotlinx.coroutines.JobCancellationException: Job was cancelled; job=SupervisorJobImpl{Cancelling}@131dbe3 All I know is the SupervisorJobImpl is for ViewModelScope, and it will be called method cancel when ViewModel lifecycle is over. I was so confused about the Exception because Kotlin coroutines will just ignore the Exception, but it was thrown and cause the App crash. If it has stack I can just figure out, but it doesn't, just tell me that the job was cancelled. I spent about more than 3 days on the exception but just have no idea. I saw the video : KotlinConf 2019: Coroutines! Gotta ca