Last active
September 27, 2017 12:04
-
-
Save 0atman/e73b0959c5468fdf081df3f6bcd6dc3f to your computer and use it in GitHub Desktop.
Hy implamentation of Clojure's awesome `future` call
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
(import [multiprocessing.pool [ThreadPool]]) | |
(defmacro future [code] | |
(def t (gensym)) | |
(def pool (ThreadPool :processes 1)) | |
`(do | |
(def ~t (pool.apply-async (fn [] ~code))) | |
~t)) |
or simply,
=> (future (print "hy"))
<multiprocessing.pool.ApplyResult object at 0x7f946bff56a0>
"hy"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: