Skip to content

Instantly share code, notes, and snippets.

@kobeumut
Created August 1, 2021 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobeumut/ccf133dc2518759ace509a7669b98909 to your computer and use it in GitHub Desktop.
Save kobeumut/ccf133dc2518759ace509a7669b98909 to your computer and use it in GitHub Desktop.
It can be used instead of coroutines in small projects
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