Created
August 1, 2021 11:26
-
-
Save kobeumut/ccf133dc2518759ace509a7669b98909 to your computer and use it in GitHub Desktop.
It can be used instead of coroutines in small projects
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
public class ApplicationExecutors { | |
private final Executor background; | |
private final Executor mainThread; | |
public Executor getBackground() { | |
return background; | |
} | |
public Executor getMainThread() { | |
return mainThread; | |
} | |
public ApplicationExecutors() { | |
this.background = Executors.newSingleThreadExecutor(); | |
this.mainThread = new MainThreadExecutor(); | |
} | |
private static class MainThreadExecutor implements Executor { | |
private Handler mainThreadHandler = new Handler( | |
Looper.getMainLooper() | |
); | |
@Override | |
public void execute(Runnable command) { | |
mainThreadHandler.post(command); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment