Last active
August 29, 2015 14:06
-
-
Save Dykam/f3c8c94a735a5c4e3b1b to your computer and use it in GitHub Desktop.
Event & Threading model proposal (Usege example)
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
// When using Java 6 or 7 | |
Observable<Vector> positions = | |
server.events.playerMove().map(new Fn<PlayerMoveEvent, Vector>() { | |
public Vector call(PlayerMoveEvent event) { | |
return event.getPlayer().getPosition(); | |
} | |
}) | |
.async() // continue on threadpool | |
.map(new Fn<Vector, Vector>() { | |
public Vector call(Vector vector) { | |
return /* do complex slow math */; | |
} | |
}) | |
.sync() // continue on main thread | |
.on(new Callback<Vector>() { | |
public void call(Vector vector) { | |
/* apply result on the main thread */; | |
} | |
}); | |
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
Observable<Vector> positions = | |
server.events.playerMove().map(event -> event.getPlayer().getPosition()) | |
.async() // continue on threadpool | |
.map(vector-> /* do complex slow math */) | |
.sync() // continue on main thread | |
.on(vector -> /* apply result on the main thread*/ ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment