Use case: I have a lot of operations that I want to happen asynchronously from the main thread but also in parallel with each other.
val scope = CoroutineScope(Dispatchers.IO)
val items = // List of items to do something.
scope.launch {
items.forEach { item ->
scope.launch {
if (itemFailsValidation(item)) {
// Here I want to skip this item but continue the forEach loop.
return@launch // "There is more than one label with such a name in this" scope"
}
doSomethingThatMightTakeABit(item)
}
}
}
If I try to add a label, like inner@scope.launch, editor says "Label is redundant, because it can not be referenced in either ''break'', ''continue'', or ''return'' expression"
Does anyone know a good way of doing this?