mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 11:28:41 +01:00
Periodically post available live data, even when invalidated
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user