madsbf
02/03/2019, 10:10 AMsuspend fun select(contentMap: Map<Content, VideoContentItemHolder>) = coroutineScope {
select<Content> {
contentMap.forEach { content, itemHolder ->
launch { itemHolder.onClick() }.onJoin {
content
}
}
}
}
VideoContentItemHolder.onClick() is a suspending function. Basically I am waiting for any of the itemHolder.onClick() to complete, and then returning the associated Content-object. I have attached the debugger to see that onClick() successfully completes for one of the itemHolders and I enter the onJoin-block, but the select clause never gets a result. So anyone waiting for the result is suspended indefinitely.altavir
02/03/2019, 10:15 AMforEach
returns Unit
madsbf
02/03/2019, 10:23 AMaltavir
02/03/2019, 10:25 AMmadsbf
02/03/2019, 10:26 AMaltavir
02/03/2019, 10:27 AMmadsbf
02/03/2019, 10:30 AMaltavir
02/03/2019, 12:00 PMcoroutineScope
is not needed here, yet I don't understand why it behaves like this.bdawg.io
02/04/2019, 8:58 AMcoroutineScope
is suspending until after all of your item holders have been clicked. If this isn't the intended behavior, cancel all of your other jobs in the onJoin:
.onJoin {
this@coroutineScope.cancelChildren()
content
}
Your select clause is completing, but your coroutineScope
won't return until all of the other launched jobs have completed. Thus preventing leaked jobs via Structured Concurrencymadsbf
02/04/2019, 1:03 PM