Use Clojure Cells or add-watcher for reactive program?
-
14-10-2019 - |
Question
I want to use alot of reactive (dataflow) type programming techniques in my clojure program. Is uses "add-watcher" on clojure refs going to be good enough to do this. A simple case for this would be to update the GUI when the underlying data changes.
Solution
Yes, that is indeed a good idea. I have used it in my own code to update UI elements when the streaming data changes. Only thing you need to be careful of is that, the watchers are called synchronously in the agent
's thread or the main thread if atom
, ref
or var
. So to avoid blocking the thread, don't do too much processing in the watchers. If you need to do so then create a future
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow