cljfx

https://github.com/cljfx/cljfx
DFST 2020-04-05T19:06:03.032100Z

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!

phronmophobic 2020-04-05T19:21:50.032600Z

do you have a main?

DFST 2020-04-05T19:25:58.032800Z

No, just

(def app
  (fx/create-app *state ...))

phronmophobic 2020-04-05T19:28:19.033100Z

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.

phronmophobic 2020-04-05T19:29:40.033300Z

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

phronmophobic 2020-04-05T19:30:27.033500Z

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

DFST 2020-04-05T19:34:22.033700Z

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.

🦜 2
DFST 2020-04-05T19:35:13.033900Z

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

phronmophobic 2020-04-05T19:48:59.034100Z

you can just start the polling in the main function

phronmophobic 2020-04-05T19:49:10.034300Z

at the same time you start your app

phronmophobic 2020-04-05T19:49:55.034600Z

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

vlaaad 2020-04-05T21:13:32.035100Z

Here is an example of a main that fires a cljfx event on start

DFST 2020-04-05T23:26:45.035600Z

Thanks! This is perfect