While reading coroutine-related articles or watchi...
# coroutines
d
While reading coroutine-related articles or watching videos, I often come upon some phrases which mark some pattern as "conventional". Here's an example from Roman Elizarov's article on coroutines. As I keep learning I keep forgetting these "conventions" which seem quite important for the general design of the code. Is there some place where all these are summarized perhaps?
2
❤️ 3
j
I don't know of such place, but it would be a nice addition indeed
d
There was another convention in some video from KotlinConf which related to using
launch
and extensions (IIRC), but I've now forgotten about that, need to find and rewatch 🙂
j
One usual convention is that
suspend
functions are supposed to finish their work before returning (basically they shouldn't launch coroutines that outlive their own execution scope). That's why they often use
coroutineScope { ... }
blocks etc to control parallel decomposition of work, but still wait for child coroutines before returning. OTOH functions that launch coroutines that outlive them should in general not be suspending, and instead they are usually declared as extensions on
CoroutineScope
(unless there is a scope already defined as a property in the containing class or something like that)
d
Nice! Thank you!
j
This tells you what not to do, so by implication it is a list of conventions.
d
thank you, bookmarked!
👍 1