pass event producer fn as param

This commit is contained in:
Daniel Barlow 2024-03-05 18:06:29 +00:00
parent 0787807a7f
commit ed9548f21d
2 changed files with 5 additions and 8 deletions

View file

@ -33,7 +33,7 @@
(when (. got params.expecting) (when (. got params.expecting)
(os.exit 0)))) (os.exit 0))))
(fn run [] (fn run [event-fn]
(let [parameters (let [parameters
(assert (parse-args arg) (assert (parse-args arg)
(.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))] (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))]
@ -41,9 +41,9 @@
(print (.. (. arg 0) ": waiting for " (print (.. (. arg 0) ": waiting for "
parameters.link " to be " parameters.expecting))) parameters.link " to be " parameters.expecting)))
(each [event (nl.events {:link true})] (each [event (event-fn)]
(run-event parameters event)))) (run-event parameters event))))
(when (not (= (. arg 0) "test")) (run)) (when (not (= (. arg 0) "test")) (run #(nl.events {:link true})))
{ : run } { : run }

View file

@ -1,18 +1,15 @@
(local fennel (require :fennel)) (local fennel (require :fennel))
(fn events [groups] (fn event-fn [groups]
(let [data (with-open [e (io.open "events-fixture" "r")] (e:read "*a")) (let [data (with-open [e (io.open "events-fixture" "r")] (e:read "*a"))
parse (fennel.parser data)] parse (fennel.parser data)]
;(print data)
(coroutine.wrap (coroutine.wrap
(fn [] (fn []
(each [ok ast parse] (each [ok ast parse]
(if ok (coroutine.yield ast))))))) (if ok (coroutine.yield ast)))))))
(tset package.loaded :anoia.nl { :events events })
(set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "test"))) (set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "test")))
(local ifwait (require :ifwait)) (local ifwait (require :ifwait))
(ifwait.run) (ifwait.run event-fn)