Created
February 1, 2013 21:18
-
-
Save k33g/4694212 to your computer and use it in GitHub Desktop.
Promise notation for N3rd.stack (and fast!>>forward)
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
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