Created
January 29, 2014 14:15
-
-
Save dgellow/8688830 to your computer and use it in GitHub Desktop.
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
(defn polling [fun] | |
(println "[polling] started") | |
(loop [] | |
(if (not (realized? fun)) | |
(recur))) | |
(println "[polling] result: " (deref fun)) | |
(println "[polling] end") | |
(deref fun)) | |
(do | |
(println "[Main] calculus") | |
(def what-is-the-answer | |
(future | |
(println "[Future] started") | |
(Thread/sleep 10000) | |
(println "[Future] completed") | |
42)) | |
(def answer-in-future | |
(future | |
(println "[Future2] started") | |
(polling what-is-the-answer) | |
(println "[Future2] completed") | |
@what-is-the-answer)) | |
(println "[Main] created future") | |
(println "[Main] do other things, waiting for answer") | |
(Thread/sleep 1000) | |
(println "[Main] get the answer") | |
(println "[Main] result: " @what-is-the-answer) | |
(println "[Main] get answer2") | |
(println "[Main] result: " @answer-in-future) | |
(println "[Main] shutdown agents") | |
(shutdown-agents) | |
(println "[Main] @what-is" @what-is-the-answer) | |
(println "[Main] end")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment