Skip to content

Instantly share code, notes, and snippets.

@rowanl
Last active January 19, 2018 22:58
Show Gist options
  • Save rowanl/911001b66f5ca0d5a413004d7709cf11 to your computer and use it in GitHub Desktop.
Save rowanl/911001b66f5ca0d5a413004d7709cf11 to your computer and use it in GitHub Desktop.
private <T> CompletionStage<T> wrapContext(Supplier<T> toRun) {
return supplyAsync(toRun, executionContext); // here we are passing the context to run the method in, this means this is running in our new actor context
}
// and here is the magic, we are returning async and we are doing it in the context of executionContext. For the JS folk this is like using call or apply, we are saying do this call, but do this call within a different context than the http thread you were called from
public CompletionStage<List<Charity>> findList() {
return wrapContext(() -> ebeanServer.find(Charity.class).findList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment