Skip to content

Instantly share code, notes, and snippets.

@Dykam
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dykam/f3c8c94a735a5c4e3b1b to your computer and use it in GitHub Desktop.
Save Dykam/f3c8c94a735a5c4e3b1b to your computer and use it in GitHub Desktop.
Event & Threading model proposal (Usege example)
// 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 */;
}
});
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