I'm writing an app where I want to poll a set of files on the hard disk to see whether they have been modified since the last time the application is aware of. I have an event set up that is able to wait a couple seconds before dispatching itself again, creating an infinite loop that will run as long as the program is going. Right now, I am starting it manually for testing, but my question is: what is the best way to fire the event automatically for the first time upon app start? Thanks very much for your help!
do you have a main?
No, just
(def app
(fx/create-app *state ...))
I would recommend adding a main so that you can load the namespace without starting it. you can also move your (def app …)
in the main.
a main is just a normal function that takes in the command line args. not sure how you’re distributing your app, but if you’re making an uberjar, you just specify your main to make that function run on startup
if you’re using lein
, then you can run it with lein run -m my.namespace/my-main-fn-name
. pretty sure bootstrap et. al have something similiar
Thanks for the pointers--(This is my first clojure project; I am not a professional developer.) I'm just prototyping an app that I thought would be useful to me personally, so I haven't thought ahead to distribution.
But I'm still not quite seeing how adding the (def app...) to main will help me fire a cljfx event when the application starts so that I can get the periodic polling I'm looking for
you can just start the polling in the main function
at the same time you start your app
moving the def app to the main function doesn’t help you with the polling issue, but I think it’s a good idea in general
Here is an example of a main that fires a cljfx event on start
Thanks! This is perfect