This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-04
Channels
- # beginners (14)
- # boot (28)
- # chestnut (9)
- # cljsrn (18)
- # clojure (64)
- # clojure-conj (1)
- # clojure-dusseldorf (45)
- # clojure-finland (4)
- # clojure-gamedev (1)
- # clojure-greece (8)
- # clojure-italy (22)
- # clojure-russia (4)
- # clojure-spec (19)
- # clojure-uk (38)
- # clojurescript (49)
- # code-reviews (2)
- # component (12)
- # core-async (3)
- # cursive (3)
- # data-science (2)
- # events (4)
- # fulcro (394)
- # heroku (3)
- # hoplon (16)
- # immutant (11)
- # jobs (5)
- # lein-figwheel (1)
- # lumo (18)
- # off-topic (8)
- # om (11)
- # other-languages (1)
- # overtone (1)
- # pedestal (7)
- # portkey (62)
- # protorepl (1)
- # re-frame (40)
- # reagent (41)
- # ring-swagger (5)
- # spacemacs (5)
- # unrepl (5)
- # yada (12)
hey guys, quick question. I just started using the components
framework from Stuart Sierra and the reload
workflow. One thing that I still dont understand is that for development he recommends to use alter-var-root
. Why not an atom
together with swap!
. I thought that is the recommended way. Is there any benefit in using vars over atoms?
I’ll take a stab at it. I don’t think it really matters? I’ve used both techniques. Using a var lets you access the system without having to deref which is a convenience, but I think the larger point may be: atoms are for coordinating access to mutable entities, while vars are for accessing constant values. During a given run, most systems are going to be constant.
@carocad atoms are for things that are changed programmatically, for something that is only redefined explicitly in a human entered top level command, a var is fine
on a related topic. Is it necessary or encourage to call stop
on production to die gracefully? for example: put a hook to SIGTERM and call stop
before exiting? or the JVM takes care of everything automatically?
https://stackoverflow.com/questions/2975248/how-to-handle-a-sigterm
Do you have any invariants not enforced automatically by the os and vm on shutdown?
Eg. membership in some distributed system that you prefer to explicitly exit rather than letting it auto timeout, or tracking of incomplete state
Also, regarding using an atom, don't do that if system startup functions have side effects, consider what would happen in retries (likely stealing a needed http port, or leaving duplicate threadpools or go blocks running)
@noisesmith yeah exactly. My question was precisely in that direction. I checked the swap!
docs and it said that f
must be free of side effects which got me wonder about it since the whole system gets shut down so I was not sure if it would really have an impact
regarding shutdown. No, not so far. But I just started using component and its workflow but I couldnt find any references to using stop
on production which got me wondering about it. But yeah I guess for most cases the OS/VM should handle that automatically. I will keep an eye on this that might need to be closed manually anyway
oh, right, if your f passed to swap! did a shutdown then start, you would just have redundant restarts but you wouldn't lose resources