Fork me on GitHub
#component
<
2017-09-04
>
carocad10:09:02

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?

donaldball13:09:13

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.

noisesmith13:09:04

@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

carocad16:09:06

ah ok. I was already doubting my Clojure knowledge 😄. Thanks guys

carocad16:09:50

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

noisesmith16:09:19

Do you have any invariants not enforced automatically by the os and vm on shutdown?

noisesmith16:09:36

Eg. membership in some distributed system that you prefer to explicitly exit rather than letting it auto timeout, or tracking of incomplete state

noisesmith17:09:59

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)

carocad21:09:08

@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

carocad21:09:15

good to know 🙂

carocad21:09:19

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

noisesmith21:09:17

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