mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Show remaining time on wave form view and cache wave form in database.
This commit is contained in:
committed by
Greyson Parrelli
parent
e01838e996
commit
3fec23fd36
@@ -0,0 +1,39 @@
|
||||
package org.thoughtcrime.securesms.util.concurrent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* From https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executor.html
|
||||
*/
|
||||
public final class SerialExecutor implements Executor {
|
||||
private final Queue<Runnable> tasks = new ArrayDeque<>();
|
||||
private final Executor executor;
|
||||
private Runnable active;
|
||||
|
||||
public SerialExecutor(@NonNull Executor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public synchronized void execute(final Runnable r) {
|
||||
tasks.offer(() -> {
|
||||
try {
|
||||
r.run();
|
||||
} finally {
|
||||
scheduleNext();
|
||||
}
|
||||
});
|
||||
if (active == null) {
|
||||
scheduleNext();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void scheduleNext() {
|
||||
if ((active = tasks.poll()) != null) {
|
||||
executor.execute(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user