Skip to content

Instantly share code, notes, and snippets.

@k33g
Created February 1, 2013 21:18
Show Gist options
  • Save k33g/4694212 to your computer and use it in GitHub Desktop.
Save k33g/4694212 to your computer and use it in GitHub Desktop.
Promise notation for N3rd.stack (and fast!>>forward)
Promise<String> promise = new Promise<String>("My batchTask as String Promise", new Batch() {
public String run() throws InterruptedException {
long duration=(long)(Math.random()*10);
System.out.println("Waiting for "+duration+" seconds for results.");
TimeUnit.SECONDS.sleep(duration);
System.out.println("Hello World by anonymous class");
return "Hello World by Anonymous";
}
});
promise.submit();
try {
TimeUnit.SECONDS.sleep(5);
System.out.println("Value of promise : " + promise.value());
} catch (InterruptedException e) {
e.printStackTrace();
}
/*
try {
TimeUnit.SECONDS.sleep(3);
promise.cancel();
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment