Hi folks,
I'm learning cljs targeting nodejs and for that I'm trying to write a simple
captcha generator code that makes use of imagemagick. This is something that I
had done before in "pure" nodejs so I figured that would be a good starting
point.
My sample code is using doo as test runner
I'd like call node's "child_process" function and wait for it to finish, so I
wrote the function below after some github surfing:
;; src/simple-aws-captcha/core.cljs
(ns simple-aws-captcha.core
(:require [cljs-lambda.util :refer [async-lambda-fn]]
[cljs.nodejs :as node]
[cljs.core.async :as async])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn exec [cmd]
(let [ch (async/chan)
ps (node/require "child_process")]
(.exec ps cmd (fn [err stdout]
(if (nil? err)
(async/put! ch stdout)
(async/put! ch "error")
)))
ch))
And to test it I wrote the following TDD code:
;; test/simple-aws-captcha/core_test.cljs
(ns simple-aws-captcha.core-test
(:require-macros [cljs.core.async.macros :refer [go alt!]])
(:require [cljs.test :refer-macros [deftest is testing async run-tests]]
[cljs.core.async :refer [>! <! chan put! take! timeout close!]]
[simple-aws-captcha.core :refer [get-code get-image exec]]))
(enable-console-print!)
(deftest call-convert-with-exec
(testing "trying to exec a simple cmd command"
(let [ch (exec "ls -al")]
(print "so far so good")
(go
(<! ch)
(print "end of go block")))))
When I ran the tests the "so far so good" string is printed, but I never got
the command result not the "end of go block".
What am I doing wrong here?
Thanks in advance,
Eric
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.