Skip to content

Instantly share code, notes, and snippets.

@dgellow
Created January 29, 2014 14:15
Show Gist options
  • Save dgellow/8688830 to your computer and use it in GitHub Desktop.
Save dgellow/8688830 to your computer and use it in GitHub Desktop.
(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