Last active
April 4, 2018 06:40
-
-
Save adamw/fe51387ca059c6124ebae38b1815b8f2 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
| class Callbacks { | |
| // I/O operations: non-blocking, asynchronous | |
| <T> void fetchFromDb(Class<T> entityClass, long id, Consumer<T> callback) { } | |
| void sendHttpGet(String url, Consumer<String> callback) { } | |
| void sendEmail(String to, String content, Runnable callback) { } | |
| // the bussines logic: asynchronous | |
| void runBusinessProcess(Runnable callback) { | |
| fetchFromDb(User.class, 42, | |
| // continuation: what should happen after the user is read from the db | |
| user -> sendHttpGet("http://profile_service/get/" + user.getProfileId(), | |
| profile -> sendEmail(user.getEmail(), | |
| "Your profile is: " + profile, | |
| callback))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment