This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-28
Channels
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
I solve this problem by adding @(promise)
after the call to listener
, at the point that I want to wait
@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.
@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
I think i might move it into a function call because atm its causing my tests not to run because its just waiting 😄
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
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)
I had looked at aleph and was wondering if i needed to make a call to its server start function but that seemed wrong.
however, in order to manually call that, you need the server
value here: https://github.com/juxt/yada/blob/master/src/yada/aleph.clj#L12
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]
Lifecycle
(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)
component)))
It seems that I can't stop the server with (.stop server) when I do
(defn new-server
([port]
(new-server port nil))
([port handler]
(map->Server {:port port :handler handler})))
(def server (new-server 3000 (yada "Hello World")))
in the repl