https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Jan Skrasek

05/07/2019, 12:24 PM
I want to run multiple async tasks that doesn't affect each other neither their parent. Eg. something like:
Copy code
(0..4)
	.map { async { .... } }
	.forEach {
		try  { 
			it.await()...process
		} catch() {}
	}
Which coroutine scope builder I should use? Using
coroutineScope {}
or
supervisorScope {}
would cancel the parent or siblings respectively.
d

Dias

05/07/2019, 12:58 PM
supervisorScope doesn't cancel siblings
n

nulldev

05/07/2019, 1:25 PM
If you want the asyncs to be cancelled when the parent is cancelled, use
supervisorScope
. If you want the asyncs to be completely isolated from the parent, use
GlobalScope
.
j

Jan Skrasek

05/07/2019, 1:27 PM
well, ideally I want them to cancelled if parent is cancelled, but not to cancel parent if they fail.