Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active April 4, 2018 05:53
Show Gist options
  • Select an option

  • Save adamw/24b2c234a7b20c2c0c3bb707c91cf669 to your computer and use it in GitHub Desktop.

Select an option

Save adamw/24b2c234a7b20c2c0c3bb707c91cf669 to your computer and use it in GitHub Desktop.
package test;
public class Compare4Synchronous {
// data structures
public class ProfileData {
public long getUserId() { return 42; }
}
public class User {
public String getEmail() { return null; }
boolean getNotificationsEnabled() { return false; }
}
// I/O operations: blocking, synchronous
<T> T fetchFromDb(Class<T> entityClass, long id) { return null; }
void sendEmail(String to, String content) { }
void sendHttpPost(String url, Object payload) { }
// the business logic: synchronous, sequence of statements
String runBusinessProcess(ProfileData profileData) {
User user = fetchFromDb(User.class, profileData.getUserId());
if (user != null) {
sendHttpPost("http://profile_service/post/" + profileData.getUserId(),
profileData);
if (user.getNotificationsEnabled()) {
sendEmail(user.getEmail(), "profile updated");
}
return "ok";
} else {
return "user not found";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment