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

kevin.cianfarini

05/22/2020, 6:18 PM
How would I go about having a
CoroutineScope
that automatically restarts jobs that have failed? Maybe with exponential backoff?
supervisorScope
doesn't quite get me there, but is a good starting point
z

Zach Klippenstein (he/him) [MOD]

05/22/2020, 6:19 PM
I don’t think a
CoroutineScope
can perform that kind of funtionality.
Job
isn’t restartable.
k

kevin.cianfarini

05/22/2020, 6:20 PM
Hm. I'm trying to think how I would differentiate which job has failed and react accordingly
my use case....
using
CoroutineWorker
as part of workmanager, I want to start several
Flows
that listen from different TCP connections for data/events. If one of those TCP connections loses connection, I'd like to be able to reconnect with exponential backoff.
differentiating which flow has failed is an interesting problem
o

octylFractal

05/22/2020, 6:28 PM
is there some reason you can't have
Flow
do the retry? that's what it's designed for
☝️ 2
k

kevin.cianfarini

05/22/2020, 6:30 PM
🤦‍♂️ thank you lol
u

uli

05/22/2020, 6:51 PM
There's also an example of a plain coroutine retry from roman elizarov: https://stackoverflow.com/a/46890009 @there's also a retry example for coroutines form
As noted in the comment, you can also inline it
3 Views