From ed9548f21d5f89f752efa77558faa32008c9d683 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 5 Mar 2024 18:06:29 +0000 Subject: [PATCH] pass event producer fn as param --- pkgs/ifwait/ifwait.fnl | 6 +++--- pkgs/ifwait/test-ifwait.fnl | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkgs/ifwait/ifwait.fnl b/pkgs/ifwait/ifwait.fnl index 9d6dd9a..f49398b 100644 --- a/pkgs/ifwait/ifwait.fnl +++ b/pkgs/ifwait/ifwait.fnl @@ -33,7 +33,7 @@ (when (. got params.expecting) (os.exit 0)))) -(fn run [] +(fn run [event-fn] (let [parameters (assert (parse-args arg) (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))] @@ -41,9 +41,9 @@ (print (.. (. arg 0) ": waiting for " parameters.link " to be " parameters.expecting))) - (each [event (nl.events {:link true})] + (each [event (event-fn)] (run-event parameters event)))) -(when (not (= (. arg 0) "test")) (run)) +(when (not (= (. arg 0) "test")) (run #(nl.events {:link true}))) { : run } diff --git a/pkgs/ifwait/test-ifwait.fnl b/pkgs/ifwait/test-ifwait.fnl index 731a2fe..17bb4a0 100644 --- a/pkgs/ifwait/test-ifwait.fnl +++ b/pkgs/ifwait/test-ifwait.fnl @@ -1,18 +1,15 @@ (local fennel (require :fennel)) -(fn events [groups] +(fn event-fn [groups] (let [data (with-open [e (io.open "events-fixture" "r")] (e:read "*a")) parse (fennel.parser data)] - ;(print data) (coroutine.wrap (fn [] (each [ok ast parse] (if ok (coroutine.yield ast))))))) -(tset package.loaded :anoia.nl { :events events }) - (set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "test"))) (local ifwait (require :ifwait)) -(ifwait.run) +(ifwait.run event-fn)