component

2017-09-04T10:22:02.000168Z

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?

donaldball 2017-09-04T13:04:13.000002Z

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.

2017-09-04T13:18:04.000020Z

@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

2017-09-04T16:18:06.000149Z

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

2017-09-04T16:19:50.000043Z

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

2017-09-04T16:57:19.000153Z

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

2017-09-04T16:58:36.000116Z

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

2017-09-04T17:00:59.000034Z

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)

2017-09-04T21:10:08.000032Z

@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

2017-09-04T21:10:15.000077Z

good to know 🙂

2017-09-04T21:12:19.000138Z

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

2017-09-04T21:15:17.000109Z

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