Fixed
Status Update
Comments
gg...@google.com <gg...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
al...@gmail.com <al...@gmail.com> #3
yea i'll take it.
su...@google.com <su...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
su...@google.com <su...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
Description
Oftentimes, we have jobs that we'd like to retry - for example, if network cuts out during a background upload - but we don't want to retry them indefinitely. It would be very useful to specify this as part of the work request, especially for jobs for which we wouldn't otherwise manually track state:
```
class MyWorker extends Worker {
@Override
WorkerResult doWork() {
try {
doSomeNetworkThing();
return WorkerResult.SUCCESS;
} catch (IOException e) {
// Oh no, the network is spotty. Retry, unless this is the Nth attempt, in which case
// just fail
if (/**/) { //
return WorkerResult.RETRY;
} else {
return WorkerResult.FAILURE;
}
}
}
}
```
It would be nice if, instead, we could do this declaratively:
```
new OneTimeWorkRequest.Builder(MyWorker.class)
.setBackoffPolicy(BackoffPolicy.exponential().withMaxRetries(10)) // let's just pretend this API exists
.build();
```
The above API would specify a policy such that, if the `MyWorker#doWork()` returns `WorkerResult.RETRY` 10 times, the scheduler will consider that to be equivalent to `WorkerResult.FAILURE`.