Last active
March 10, 2020 12:36
-
-
Save abarnash/9e5f1305f8f946426dd2 to your computer and use it in GitHub Desktop.
Clojure implementation of all(promises).then(...) pattern from JavaScript
This file contains hidden or 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
(defn getPromiseFn | |
[aPromise] | |
(fn [num] (Thread/sleep 10000) | |
(deliver aPromise (str num " done")))) | |
(def proms [(promise) (promise) (promise)]) | |
(def promFns (map getPromiseFn proms)) | |
(future (map deref proms)) | |
(future (map promFn (range 0 (count proms)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment