Created
August 23, 2020 04:00
-
-
Save mingwei-li/ab18a8a41a883c8a359c8bbc217997ff to your computer and use it in GitHub Desktop.
This file contains 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
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