Last active
January 3, 2016 21:49
-
-
Save grzm/8524580 to your computer and use it in GitHub Desktop.
Attempt to straight-line sequential callbacks using core.async
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 node-async.core | |
(:require-macros [cljs.core.async.macros :refer [go]] | |
[node-async.macros :refer [<?]]) | |
(:require [cljs.core.async :refer [take!]] | |
[node-async.task :refer [run-task]])) | |
;; run-task and <? appropriated from dnolen | |
;; https://gist.github.com/swannodette/6385166 | |
;; https://github.com/swannodette/swannodette.github.com/blob/master/code/blog/src/blog/utils/macros.clj | |
;; https://github.com/swannodette/swannodette.github.com/blob/master/code/blog/src/blog/utils/helpers.cljs | |
(defn first-async [args callback] | |
(.log js/console (str "(first-async " args ")")) | |
(.nextTick js/process #(callback args))) | |
(defn second-async [args callback] | |
(.log js/console (str "(second-async " args ")")) | |
(.nextTick js/process #(callback args))) | |
(defn handler [args] | |
(.log js/console (str "(handler-2 " args ")")) | |
(go | |
(let [first-res (<? (run-task first-async args)) | |
xformed (.toUpperCase first-res) | |
second-res (<? (run-task second-async xformed))] | |
(.log js/console (str "first-res: " first-res )) | |
(.log js/console (str "xformed: " xformed)) | |
(.log js/console (str "second-res: " second-res))))) | |
(defn -main [& args] | |
(handler "something-to-handle") | |
(.log js/console "started main")) | |
(set! *main-cli-fn* -main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment