mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-21 21:57:19 +00:00
Post computed live data ASAP
This commit is contained in:
parent
f0b369225f
commit
cc7ad90c48
2 changed files with 13 additions and 9 deletions
|
@ -89,6 +89,7 @@ public abstract class ComputableLiveData<T> {
|
|||
@Override
|
||||
public void run() {
|
||||
boolean computed;
|
||||
boolean once;
|
||||
long last;
|
||||
do {
|
||||
computed = false;
|
||||
|
@ -96,12 +97,14 @@ public abstract class ComputableLiveData<T> {
|
|||
if (mComputing.compareAndSet(false, true)) {
|
||||
// as long as it is invalid, keep computing.
|
||||
try {
|
||||
once = true;
|
||||
last = android.os.SystemClock.elapsedRealtime();
|
||||
T value = null;
|
||||
while (mInvalid.compareAndSet(true, false)) {
|
||||
long now = android.os.SystemClock.elapsedRealtime();
|
||||
if (last + 1500 < now && value != null) {
|
||||
eu.faircode.email.Log.i(mLiveData + " post age=" + (now - last));
|
||||
if (value != null && (once || last + 2500 < now)) {
|
||||
eu.faircode.email.Log.i(mLiveData + " post once=" + once + " age=" + (now - last) + " ms");
|
||||
once = false;
|
||||
last = now;
|
||||
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
|
||||
index 837a35dbf..338af5c89 100644
|
||||
--- a/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
|
||||
+++ b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
|
||||
@@ -89,14 +89,22 @@ public abstract class ComputableLiveData<T> {
|
||||
--- /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
|
||||
@Override
|
||||
public void run() {
|
||||
boolean computed;
|
||||
+ boolean once;
|
||||
+ long last;
|
||||
do {
|
||||
computed = false;
|
||||
|
@ -13,12 +12,14 @@ index 837a35dbf..338af5c89 100644
|
|||
if (mComputing.compareAndSet(false, true)) {
|
||||
// as long as it is invalid, keep computing.
|
||||
try {
|
||||
+ once = true;
|
||||
+ last = android.os.SystemClock.elapsedRealtime();
|
||||
T value = null;
|
||||
while (mInvalid.compareAndSet(true, false)) {
|
||||
+ long now = android.os.SystemClock.elapsedRealtime();
|
||||
+ if (last + 1500 < now && value != null) {
|
||||
+ eu.faircode.email.Log.i(mLiveData + " post age=" + (now - last));
|
||||
+ if (value != null && (once || last + 2500 < now)) {
|
||||
+ eu.faircode.email.Log.i(mLiveData + " post once=" + once + " age=" + (now - last) + " ms");
|
||||
+ once = false;
|
||||
+ last = now;
|
||||
+ mLiveData.postValue(value);
|
||||
+ }
|
||||
|
|
Loading…
Reference in a new issue