Fork me on GitHub
Matt Butler15:08:57

Hi, does anyone have any advice for using yada with leiningen? Its my understanding that lein wants a function to run when you do “lein run” however when you put a yada listener function call inside the -main function it executes the function then terminates the thread (i assume). If i put the server declaration outside of the -main function (see snippet) it runs fine but only in the repl/when running tests as they leave the process for as long as required. I’m guessing i need some way of telling lein to just wait? I’m new to clojure so apologies if i’ve made some mistakes.


@mbutler i would suggest adding a dev/user.clj or something to put the -main function in for development


just add that as an extra source path for :dev


I solve this problem by adding @(promise) after the call to listener, at the point that I want to wait


this is, in a roundabout way, the same way the edge sample application does it

Matt Butler15:08:36

@lmergen thanks, sorry if i misunderstand but would that not still have the same problem of just exiting out after the main function has run.

Matt Butler15:08:00

@bhagany Thanks, that seemed to work 😄, atm i just have the def server at the bottom of my core file so i added @(promise) under it.


yes, that ought to do it - fwiw, I think your original idea to do this inside -main is good too


(it's basically what I do)

Matt Butler15:08:57

I think i might move it into a function call because atm its causing my tests not to run because its just waiting 😄


heh, yeah, I didn't think of that

Matt Butler16:08:34

well either way thank you very much, that had been weighing over me for a while 😄


sure, no problem. I had the same question only a few weeks ago, just paying it forward 🙂


ah sorry @mbutler, i probably read too quick. for what it’s worth, boot internally also uses the @(promise) technique, and I use that in production as well

Matt Butler16:08:54

Yeah I had considered using boot as that is what edge uses but happy to find a solution 🙂 thanks again


i do think it would make sense if yada would expose netty’s wait until complete function, but i guess that would only lock yada in even more in a specific vendor (aleph)

Matt Butler16:08:43

I had looked at aleph and was wondering if i needed to make a call to its server start function but that seemed wrong.


aleph uses netty, and netty exposes the function we need to use


however, in order to manually call that, you need the server value here:


which is not exposed by yada


so you cannot do it


i think the best way forward is to expose a :wait function in that listener, similar to :close:, that blocks until the server has exited gracefully


@malcolmsparks what are your thoughts on this ? this issue seems to pop up once in a while, and I think this should be handled by yada in some way


is it normal that when I start a yada server in aleph to take 1GB of my ram?


another thing... is this the correct way to manipulate a server instance in the repl?

(defrecord Server [port server handler]
  (start [component]
    (let [server (start-server
                  (make-handler handler)
                  {:port port :join? false})]
      (assoc component :server server)))
  (stop [component]
    (when-let [server (get component :server)]
      (.close server)
It seems that I can't stop the server with (.stop server) when I do
(defn new-server
   (new-server port nil))
  ([port handler]
   (map->Server {:port port :handler handler})))

(def server (new-server 3000 (yada "Hello World")))
in the repl