use of org.thoughtcrime.securesms.util.concurrent.SerialMonoLifoExecutor in project Signal-Android by WhisperSystems.
the class LiveDataUtil method mapAsync.
/**
* Runs the {@param backgroundFunction} on the supplied {@param executor}.
* <p>
* Regardless of the executor supplied, the background function is run serially.
* <p>
* The background function may not run for all {@param source} updates. Later updates taking priority.
*/
public static <A, B> LiveData<B> mapAsync(@NonNull Executor executor, @NonNull LiveData<A> source, @NonNull Function<A, B> backgroundFunction) {
MediatorLiveData<B> outputLiveData = new MediatorLiveData<>();
Executor liveDataExecutor = new SerialMonoLifoExecutor(executor);
outputLiveData.addSource(source, currentValue -> {
liveDataExecutor.execute(() -> {
outputLiveData.postValue(backgroundFunction.apply(currentValue));
});
});
return outputLiveData;
}
use of org.thoughtcrime.securesms.util.concurrent.SerialMonoLifoExecutor in project Signal-Android by signalapp.
the class LiveDataUtil method mapAsync.
/**
* Runs the {@param backgroundFunction} on the supplied {@param executor}.
* <p>
* Regardless of the executor supplied, the background function is run serially.
* <p>
* The background function may not run for all {@param source} updates. Later updates taking priority.
*/
public static <A, B> LiveData<B> mapAsync(@NonNull Executor executor, @NonNull LiveData<A> source, @NonNull Function<A, B> backgroundFunction) {
MediatorLiveData<B> outputLiveData = new MediatorLiveData<>();
Executor liveDataExecutor = new SerialMonoLifoExecutor(executor);
outputLiveData.addSource(source, currentValue -> {
liveDataExecutor.execute(() -> {
outputLiveData.postValue(backgroundFunction.apply(currentValue));
});
});
return outputLiveData;
}
Aggregations