Hello all, Why this don´t work?
(defn inicia []
(for [id (range 10)]
(println "ID => " id)))
(defstate shaper
:start (inicia) )
@fabrao: for
is lazy
i.e.
dev=> (defn inicia [] (for [id (range 10)] (println "ID => " id)))
#'dev/inicia
dev=> (defstate shaper :start (inicia))
">> starting.. #'dev/shaper (namespace was recompiled)"
#'dev/shaper
dev=> shaper
ID => 0
ID => 1
ID => 2
ID => 3
ID => 4
ID => 5
ID => 6
ID => 7
ID => 8
ID => 9
(nil nil nil nil nil nil nil nil nil nil)
if you'd like to see results on start, use doseq
i.e.
(defn inicia [] (doseq [id (range 10)] (println "ID => " id)))
@tolitius: well, I´d like to set the results to shaper, as for returns
you'd like shaper
to initialize to (nil nil nil nil nil nil nil nil nil nil)
?
because that is what (for [id (range 10)] (println "ID => " id))
returns
in case you just want a range
:
dev=> (defstate foo :start (range 10))
#'dev/foo
dev=> (mount/start #'dev/foo)
{:started ["#'dev/foo"]}
dev=> foo
(0 1 2 3 4 5 6 7 8 9)
I tried with overtone.at-at that creates a schedule object, but I had to call shaper in repl to processes starting up
that´s because I tried with println, to see if the prints out
what would you like shaper
to be once started?
I read the config from file that define devices to monitoring, from config file that returns a list of devices, on each I want to start a schedule with overtone.at-at
(for [device (:device config)]
(let
[nome-device (name (key device))
conf-device ((key device) (:device config))
cadencia (Integer. (:cadencia (:shaper conf-device)))]
(log/debug (str "Iniciando processo Traffic Shaper para " nome-device))
(at/every (* cadencia 1000) #(processo-shaper nome-device conf-device storage) pool :desc nome-device :fixed-delay true)))
right, so for
is lazy, if you'd like them to be scheduled when this expression is called, use doseq
ok, so I have to include the instances in a list to return
I´ll try with doseq
ok, so you want this list of futures?
yes, because in :stop the schedules jobs must be stoped
dev=> (defn inicia []
(doall (for [id (range 10)]
(let [foo 42]
(println "ID => " id)
(+ id foo)))))
#'dev/inicia
dev=> (defstate fooz :start (inicia))
#'dev/fooz
dev=> (mount/start #'dev/fooz)
ID => 0
ID => 1
ID => 2
ID => 3
ID => 4
ID => 5
ID => 6
ID => 7
ID => 8
ID => 9
{:started ["#'dev/fooz"]}
dev=> fooz
(42 43 44 45 46 47 48 49 50 51)
HUMMMMMM, I´ll try it
doall
realizes lazy seqs
the problem was I didn´t know that lazy seqs don´t work with mount start, thanks a lot 4 ur help
sure. lazy seqs work with mount/start
i.e. a state becomes a lazy seq. but in your case you do not need a lazy seq, since you'd like these calls to every
executed as the function is called.
I changed including doall and it works, thanks for your help
sure, glad it works for you 🙂
A question, if a start blocks in a loop, the starting system will freeze up?
right, a start function should return
otherwise the state will not/never have the value until the loop is done