This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-07
Channels
- # aleph (1)
- # beginners (152)
- # cider (26)
- # clara (2)
- # cljs-dev (13)
- # cljsrn (5)
- # clojure (198)
- # clojure-greece (15)
- # clojure-italy (39)
- # clojure-sanfrancisco (3)
- # clojure-spec (28)
- # clojure-uk (16)
- # clojurescript (52)
- # community-development (15)
- # core-async (26)
- # cursive (42)
- # data-science (28)
- # datomic (19)
- # devops (7)
- # duct (11)
- # emacs (24)
- # fulcro (22)
- # garden (4)
- # leiningen (12)
- # luminus (1)
- # mount (5)
- # off-topic (106)
- # om (5)
- # onyx (10)
- # parinfer (37)
- # re-frame (17)
- # reagent (47)
- # shadow-cljs (36)
- # yada (2)
@mjmeintjes it'd be helpful to know the actual use case:
* who calls a .close
function: is done via mount of called somewhere else?
* what is it that is needed to be done in a done
function?
* if .close
is called as a part of "mount/stop" why does mount need to wait for a callback to be called?
Just a disclaimer - there is a distinct possibility that I'm doing this wrong, as I'm pretty new to node.
I have 2 functions, start
and stop
, that gets called when app is started and stopped/reloaded. In start
I call mount/start
, in stop
I call mount/stop
.
The stop function is async, and takes a done
callback that it just calls to indicate that processing is done.
(defn start
"Hook to start. Also used as a hook for hot code reload."
[]
(js/console.warn "start called")
(mount/start))
(defn stop
"Hot code reload hook to shut down resources so hot code reload can work"
[done]
(js/console.warn "stop called")
(mount/stop)
;; not really done, as server might still be closing
(done))
I want to be able to pass that done function to the stop function, in order to signal that shutdown is finished:
(defstate server
:start (let [host (or (:host @env) "127.0.0.1")
port (or (some-> @env :port js/parseInt) 3000)]
(http/start
{:handler (wrap-defaults router)
:host host
:port port
:on-success #(info "funnels-cljs started on" host ":" port)}))
:stop (do
(println "CLOSING SERVER")
(.close @server
(fn []
;; want to call the done callback here
))))
@mjmeintjes
> in order to signal that shutdown is finished
If I understood correctly you need to log a message that confirms that the server is shutdown. Instead of calling (done)
in a defined "stop" function, could you just pass it as it is intended to .close
:
(.close @server
(fn []
(done)
))
?No, not as far as I know, as I only get a reference to the done callback in that stop function, which is called by shadow-cljs when code is reloaded. The stop function is just there to tell shadow-cljs that the app has stopped and that it can now reload safely.
@mjmeintjes I have not used shadow-cljs
, it looks like it also in a way manages state hence the hiccup. If a done
function is something known in advance:
(.close @server
(fn []
(done)
))
will be an option
in case done
is an internal fn passed by shadow-cljs
, you could probably place :done
on the async channel in the callback, and then read it to report that is was called