Post computed live data ASAP

pull/161/head
M66B 6 years ago
parent f0b369225f
commit cc7ad90c48

@ -89,6 +89,7 @@ public abstract class ComputableLiveData<T> {
@Override @Override
public void run() { public void run() {
boolean computed; boolean computed;
boolean once;
long last; long last;
do { do {
computed = false; computed = false;
@ -96,12 +97,14 @@ public abstract class ComputableLiveData<T> {
if (mComputing.compareAndSet(false, true)) { if (mComputing.compareAndSet(false, true)) {
// as long as it is invalid, keep computing. // as long as it is invalid, keep computing.
try { try {
once = true;
last = android.os.SystemClock.elapsedRealtime(); last = android.os.SystemClock.elapsedRealtime();
T value = null; T value = null;
while (mInvalid.compareAndSet(true, false)) { while (mInvalid.compareAndSet(true, false)) {
long now = android.os.SystemClock.elapsedRealtime(); long now = android.os.SystemClock.elapsedRealtime();
if (last + 1500 < now && value != null) { if (value != null && (once || last + 2500 < now)) {
eu.faircode.email.Log.i(mLiveData + " post age=" + (now - last)); eu.faircode.email.Log.i(mLiveData + " post once=" + once + " age=" + (now - last) + " ms");
once = false;
last = now; last = now;
mLiveData.postValue(value); mLiveData.postValue(value);
} }

@ -1,11 +1,10 @@
diff --git a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java --- /home/marcel/support/lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/ComputableLiveData.java 2019-07-27 12:47:44.348985792 +0200
index 837a35dbf..338af5c89 100644 +++ app/src/main/java/androidx/lifecycle/ComputableLiveData.java 2019-08-14 10:25:21.881453609 +0200
--- a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java @@ -89,14 +89,25 @@ public abstract class ComputableLiveData
+++ b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
@@ -89,14 +89,22 @@ public abstract class ComputableLiveData<T> {
@Override @Override
public void run() { public void run() {
boolean computed; boolean computed;
+ boolean once;
+ long last; + long last;
do { do {
computed = false; computed = false;
@ -13,12 +12,14 @@ index 837a35dbf..338af5c89 100644
if (mComputing.compareAndSet(false, true)) { if (mComputing.compareAndSet(false, true)) {
// as long as it is invalid, keep computing. // as long as it is invalid, keep computing.
try { try {
+ once = true;
+ last = android.os.SystemClock.elapsedRealtime(); + last = android.os.SystemClock.elapsedRealtime();
T value = null; T value = null;
while (mInvalid.compareAndSet(true, false)) { while (mInvalid.compareAndSet(true, false)) {
+ long now = android.os.SystemClock.elapsedRealtime(); + long now = android.os.SystemClock.elapsedRealtime();
+ if (last + 1500 < now && value != null) { + if (value != null && (once || last + 2500 < now)) {
+ eu.faircode.email.Log.i(mLiveData + " post age=" + (now - last)); + eu.faircode.email.Log.i(mLiveData + " post once=" + once + " age=" + (now - last) + " ms");
+ once = false;
+ last = now; + last = now;
+ mLiveData.postValue(value); + mLiveData.postValue(value);
+ } + }

Loading…
Cancel
Save