Skip to content

Instantly share code, notes, and snippets.

@kachayev
Last active January 27, 2019 19:15
Show Gist options
  • Save kachayev/a279a728a4a73f16aabbebaedb94ea95 to your computer and use it in GitHub Desktop.
Save kachayev/a279a728a4a73f16aabbebaedb94ea95 to your computer and use it in GitHub Desktop.
(require '[manifold.deferred :as d])
(defn long-boring-computation []
(let [result (d/deferred)]
(d/future
(dotimes [_ 100]
(when-not (d/realized? result)
;; block the thread is still a bad idea :(
(Thread/sleep 1e3)))
(d/success! result "I'm done with this"))
result)))
(def f1 (long-boring-computation))
;; we're already running
(d/error! f1 (Exception. "I don't need this, sorry"))
;; will stop on the next iteration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment