Skip to content

Instantly share code, notes, and snippets.

@elfenlaid
Created October 13, 2014 21:54
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 elfenlaid/14ab3cc6bc4e6a93d0ae to your computer and use it in GitHub Desktop.
Save elfenlaid/14ab3cc6bc4e6a93d0ae to your computer and use it in GitHub Desktop.
(defn waitForFuture [timeout & refs] (doseq [r refs] (deref r timeout nil)))
(def phrase (ref "hello"))
(waitForFuture 1
(future (dosync (println "will rename phrase") (Thread/sleep 100) (ref-set phrase "world")))
(future (dosync (println (ensure phrase)) (Thread/sleep 3000) (println (ensure phrase)))))
will rename phrase
hello
nil
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
will rename phrase
hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment