Last active
April 26, 2019 20:39
-
-
Save 4mitch/a34f513cfd8e163c24645aca775b3e54 to your computer and use it in GitHub Desktop.
CLJS uses js promises
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
(defn subtask+ [] | |
(js/Promise. (fn [resolve] | |
(js/setTimeout #(resolve :success) 5000))) | |
) | |
(defn main [] | |
(-> (subtask+) | |
(.then (fn [result] (println "Got " result) )) | |
(.catch (fn [e] (println "Shit happend! " e )) ) | |
)) | |
(println "Start") | |
(main) | |
(println "End") | |
(defn subtask1+ [] | |
(js/Promise. (fn [resolve] | |
(js/setTimeout #(resolve :success) 5000) | |
(println "Subtask1+ at once! " ))) | |
) | |
(defn subtask2+ [arg] | |
(js/Promise. (fn [resolve] | |
(js/setTimeout #(resolve :success) 3000) | |
(println "Subtask2+ at once! " ))) | |
) | |
(defn subtask3+ [arg] | |
(js/Promise. (fn [resolve] | |
(js/setTimeout #(resolve :success) 4000) | |
(println "Subtask3+ at once! " ))) | |
) | |
(defn main [] | |
(-> (subtask+) | |
(.then (fn [result] (println "Got " result) )) | |
(.catch (fn [e] (println "Shit happend! " e )) ) | |
)) | |
(defn composite-task [] | |
(-> (subtask1+) | |
(.then (fn [result] (subtask2+ result) )) | |
(.then (fn [result] (subtask3+ result) )) | |
(.catch (fn [e] (println "Shit happend! " e )) ) | |
)) | |
(println "Start") | |
(composite-task) | |
(println "End") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment