Skip to content

Instantly share code, notes, and snippets.

@mingwei-li
Created August 23, 2020 04:00
Show Gist options
  • Save mingwei-li/ab18a8a41a883c8a359c8bbc217997ff to your computer and use it in GitHub Desktop.
Save mingwei-li/ab18a8a41a883c8a359c8bbc217997ff to your computer and use it in GitHub Desktop.
boolean updateValue(Event event) {
long userInitiatedTimestamp = event.getUserInitiatedTimestamp();
String userId = event.getUserId();
User user = database.query(userId);
long lastUserInitiatedTimestamp = user.getLastUserInitiatedTimestamp();
// event arrives in correct order
if(userInitiatedTimestamp > lastUserInitiatedTimestamp) {
// register with latest timestamp
user.setLastUserInitiatedTimestamp(userInitiatedTimestamp);
user.setValue(event.getPayloadValue());
return true;
}
else {
// ignored
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment