Skip to content

Instantly share code, notes, and snippets.

@kcleereman
Last active August 29, 2015 14:24
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 kcleereman/f8f11d010f88df5b36ce to your computer and use it in GitHub Desktop.
Save kcleereman/f8f11d010f88df5b36ce to your computer and use it in GitHub Desktop.
Creation of CancellableStatement
public class Immutable {
private final ExecutorService priorityExecutorService;
private final ExecutionContext priorityExecutionContext;
public Immutable() {
this.priorityExecutorService = Executors.newCachedThreadPool();
this.priorityExecutionContext = ExecutionContexts.fromExecutorService(priorityExecutorService);
}
public CancellableStatement getCancellableStatement(Promise<String> cancellation) {
CancellableStatement cancellableStatement = new CancellableStatement(priorityExecutorService, cancellation, listener);
cancellation.future().onFailure(new OnFailure() {
@Override
public void onFailure(Throwable failure) {
cancellableStatement.cancel();
}
}, priorityExecutionContext);
return cancellableStatement;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment