This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-01
Channels
- # announcements (26)
- # babashka (58)
- # bangalore-clj (1)
- # beginners (48)
- # bitcoin (1)
- # chlorine-clover (9)
- # clara (7)
- # clj-kondo (11)
- # cljs-dev (10)
- # cljsrn (36)
- # clojars (11)
- # clojure (161)
- # clojure-europe (39)
- # clojure-italy (2)
- # clojure-nl (6)
- # clojure-uk (14)
- # clojured (1)
- # clojurescript (38)
- # conjure (25)
- # core-async (18)
- # cursive (19)
- # datascript (9)
- # datomic (11)
- # emacs (10)
- # events (2)
- # figwheel-main (2)
- # fulcro (44)
- # funcool (5)
- # girouette (1)
- # graalvm (6)
- # jobs (1)
- # lsp (93)
- # malli (3)
- # membrane (3)
- # off-topic (17)
- # pedestal (2)
- # polylith (12)
- # re-frame (2)
- # remote-jobs (1)
- # shadow-cljs (47)
- # specter (2)
- # startup-in-a-month (1)
- # tools-deps (4)
interesting new library. Any thoughts from here? https://clojurians.slack.com/archives/C06MAR553/p1614592215160400
Let me know if you have any questions about it. I’ve been using core.async for a quite a long time now. Been through multiple iterations of a pattern to manage go-loop’s on the REPL and in a live system (both in Clojure and ClojureScript). It does use a stateful atom inside the library. This currently seems like a decent compromise between simplicity and ease of use.
I'm not sure how it compares to constantly polling a stop channel, but since you're using the stop channel as a promise and just wait for stop and pass other signals, why not just use an AtomicBoolean? Might also want to remove the timbre dependency and allow the user to inject their own logger with tools.logging
I would like it to be a Clojure(Script) library (in fact using it primarily from Cljs now); I guess AtomicBoolean can be used as an optimization on Clojure JVM
Feel free to steal ideas from https://github.com/halgari/com.tbaldridge.hermod regarding implementing a global registry, as well
I have seen this library a long time ago, but I forgot about it 🙂 Will take a look again.
It's not exactly in Erlang-land. Erlang brings with it a whole framework and model https://github.com/suprematic/otplike
Right… I’ve heard (perhaps from Timothy Baldridge while watching his talks) the concept of Erlang described via the mailboxes analogy; basically in Erlang you’re somebody who can only communicate with others via message passing (as if you’re stuck in mailbox); That’s about the extent of my knowledge on the topic 🙂
I've been using a "derefable mult" lately, which is like core.async/mult
but can be deref'd for the most recent value. I've been in situations a lot where I want a dataflow graph that is essentially a DAG but then more complicated state machines at the leaves. I also have a UI layer where I want to just be able to get a best effort recent value to show. Any thoughts why this might be a bad or good idea?
(defn dmult
"like core.async mult, but can be deref'd for the most recent input value"
[ch]
(let [cs (atom {}) ;;ch->close?
prev (atom nil)
m (reify
a/Mux
(muxch* [_] ch)
a/Mult
(tap* [_ ch close?] (swap! cs assoc ch close?) nil)
(untap* [_ ch] (swap! cs dissoc ch) nil)
(untap-all* [_] (reset! cs {}) nil)
#?@(:clj
[clojure.lang.IDeref
(deref [this] @prev)]
:cljs
[IDeref
(-deref [this] @prev)]))
dchan (chan 1)
dctr (atom nil)
done (fn [_] (when (zero? (swap! dctr dec))
(a/put! dchan true)))]
(go-loop []
(let [val (<! ch)]
(if (nil? val)
(doseq [[c close?] @cs]
(when close? (a/close! c)))
(let [chs (keys @cs)]
(reset! dctr (count chs))
(doseq [c chs]
(when-not (a/put! c val done)
(a/untap* m c)))
;;wait for all
(when (seq chs)
(<! dchan))
(reset! prev val) ;;should this go before or after all puts?
(recur)))))
m))