|
|
|
@ -16,6 +16,8 @@
|
|
|
|
|
|
|
|
|
|
package androidx.lifecycle;
|
|
|
|
|
|
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.MainThread;
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.RestrictTo;
|
|
|
|
@ -89,14 +91,22 @@ public abstract class ComputableLiveData<T> {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
boolean computed;
|
|
|
|
|
long age;
|
|
|
|
|
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 {
|
|
|
|
|
age = SystemClock.elapsedRealtime();
|
|
|
|
|
T value = null;
|
|
|
|
|
while (mInvalid.compareAndSet(true, false)) {
|
|
|
|
|
long now = SystemClock.elapsedRealtime();
|
|
|
|
|
if (age + 1500 < now && value != null) {
|
|
|
|
|
eu.faircode.email.Log.i(mLiveData + " post age=" + (now - age));
|
|
|
|
|
age = now;
|
|
|
|
|
mLiveData.postValue(value);
|
|
|
|
|
}
|
|
|
|
|
computed = true;
|
|
|
|
|
value = compute();
|
|
|
|
|
}
|
|
|
|
|