2019-08-14 08:33:34 +00:00
|
|
|
--- /home/marcel/support/lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/ComputableLiveData.java 2019-07-27 12:47:44.348985792 +0200
|
|
|
|
+++ app/src/main/java/androidx/lifecycle/ComputableLiveData.java 2019-08-14 10:25:21.881453609 +0200
|
|
|
|
@@ -89,14 +89,25 @@ public abstract class ComputableLiveData
|
2019-07-06 08:51:16 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
boolean computed;
|
2019-08-14 08:33:34 +00:00
|
|
|
+ boolean once;
|
2019-07-06 08:51:16 +00:00
|
|
|
+ long last;
|
|
|
|
do {
|
|
|
|
computed = false;
|
|
|
|
// compute can happen only in 1 thread but no reason to lock others.
|
|
|
|
if (mComputing.compareAndSet(false, true)) {
|
|
|
|
// as long as it is invalid, keep computing.
|
|
|
|
try {
|
2019-08-14 08:33:34 +00:00
|
|
|
+ once = true;
|
2019-07-06 08:51:16 +00:00
|
|
|
+ last = android.os.SystemClock.elapsedRealtime();
|
|
|
|
T value = null;
|
|
|
|
while (mInvalid.compareAndSet(true, false)) {
|
|
|
|
+ long now = android.os.SystemClock.elapsedRealtime();
|
2019-08-14 08:33:34 +00:00
|
|
|
+ if (value != null && (once || last + 2500 < now)) {
|
|
|
|
+ eu.faircode.email.Log.i(mLiveData + " post once=" + once + " age=" + (now - last) + " ms");
|
|
|
|
+ once = false;
|
2019-07-06 08:51:16 +00:00
|
|
|
+ last = now;
|
|
|
|
+ mLiveData.postValue(value);
|
|
|
|
+ }
|
|
|
|
computed = true;
|
|
|
|
value = compute();
|
|
|
|
}
|