Created
February 11, 2015 14:52
-
-
Save fge/e26cf30275a067de96ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Run a task in the background producing a value; schedule a task consuming | |
| * that value to run on the UI thread | |
| * | |
| * @param supplier the background task producing a value | |
| * @param consumer the UI thread task consuming that value | |
| * @param <T> type parameter of the produced/consume value | |
| */ | |
| public <T> void compute( | |
| @OnBackgroundThread final Supplier<? extends T> supplier, | |
| @OnUiThread final Consumer<? super T> consumer) | |
| { | |
| Objects.requireNonNull(supplier); | |
| Objects.requireNonNull(consumer); | |
| executor.submit(() -> { | |
| final T t = supplier.get(); | |
| frontExecutor.execute(() -> consumer.accept(t)); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment