Last active
December 25, 2015 04:49
-
-
Save jebberjeb/6919854 to your computer and use it in GitHub Desktop.
future-cancelled?
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
(ns test-app.core) | |
(defn do-it-slow! | |
[sleep-time] | |
(Thread/sleep sleep-time)) | |
(defn mk-future | |
[sleep-time] | |
(future (do-it-slow! sleep-time))) | |
(defn kill-future | |
[f delay] | |
(future | |
(Thread/sleep delay) | |
(future-cancel f))) | |
(def f (mk-future 10000)) | |
(try | |
(kill-future f 1000) | |
(println "derefing future, will be blocked") | |
(deref f) | |
(catch Exception e | |
(if (future-cancelled? f) | |
(println "future was cancelled while blocking at deref") | |
(throw e)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment