Is it acceptable to save multiple job instances from separate coroutines. Let's say i want to run a couple coroutines at once in which they are unrelated and cannot happen in one coroutine but i want them to run parallel. In Android i should be saving the job instance so i can cancel the job in the onDestroy method. Would it be acceptable to save each job separately in a list or am i breaking some kind of rule. I know in RX they have Subscriptions why isn't there an equivalent in Kotlin Coroutines?
val jobList = arrayListOf<Job>()
fun startJob1() {
jobList.add(launch {
//do some work
})
fun startJob1() {
jobList.add(launch {
//do some other unrelated work
})
override fun onDestroy() {
super.onDestroy()
cancelAllActiveJobs(jobList)
}
Does this type of architecture make sense for coroutines?