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

eddy_wm

01/14/2018, 10:15 AM
Hi. Is it possible in Kotlin coroutines to launch a thousand of coroutines in a way that when the first completes its execution all of other coroutines should also stop. It's quite a common pattern for parallel CPU mining algorithms.
v

voddan

01/14/2018, 10:30 AM
You could make your coroutines write something into a all-to-all channel when they complete the task. That would work as a signal co cancel all calculations
Or just cancel all coroutines when one of them returns. That can be done with a channel as well.
Basically any ad-hock way will work
e

eddy_wm

01/14/2018, 10:39 AM
Can you give me a code example of what you propose where coroutines are launched and after some time one passes a message to the channel to tell others to stop.
v

voddan

01/14/2018, 11:18 AM
@eddy_wm Sure. Would you mind creating a StackOverflow question out of it, so that it is searchable?
e

eddy_wm

01/14/2018, 1:09 PM
@voddan You can still post the code here. It will be just fine.
9 Views