This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-17
Channels
- # aleph (57)
- # announcements (2)
- # babashka (11)
- # beginners (55)
- # calva (18)
- # cider (37)
- # clj-kondo (24)
- # clojure (18)
- # clojure-europe (80)
- # clojure-nl (2)
- # clojure-norway (22)
- # clojure-uk (7)
- # clojured (1)
- # clojurescript (24)
- # data-science (9)
- # datomic (45)
- # events (1)
- # gratitude (4)
- # humbleui (30)
- # hyperfiddle (7)
- # introduce-yourself (2)
- # malli (3)
- # missionary (12)
- # music (1)
- # off-topic (33)
- # re-frame (3)
- # reagent (11)
- # ring (23)
- # shadow-cljs (13)
- # sql (3)
- # tools-deps (4)
How should I go about learning JVM async and concurrency? Open to book suggestions etc :^). Mostly interested in learning what underlies Missionary.
For learning purposes I tried implementing mi/seed by hand. Is this correct? Any bugs?
(defn seed [coll]
(fn flow [notifier terminator]
(let [remaining (atom (seq coll))]
(notifier)
(reify
IFn
(invoke [iter])
IDeref
(deref [iter]
(let [retval (first @remaining)]
(swap! remaining rest)
(if (empty? @remaining)
(terminator)
(notifier))
retval))))))
the actual implementation also crashes on cancellation, which prevents an infinite sequence from running into an infinite loop
ah true! I’ll have a look at the cancellation implementaiton 🤓 thanks!
From https://github.com/leonoel/flow#specification: > It may throw an exception to indicate a failure, in this case it must not call the notifier again. Would it be correct to say: > It may throw an exception to indicate a failure, in this case it must not call the notifier again. It must throw an exception if terminator has been called.
you mean what should happen if the consumer calls deref
without having been notified ?
I just misunderstood the mi/seed cancellation mechanism. I assumed that after cancelling it would crash by making deref throw an exception. I’ll take a further look at mi/seed cancellation tomorrow :^)
> I assumed that after cancelling it would crash by making deref throw an exception. This is correct
I got my terminology conflated in my previous message. I meant to say: > It may throw an exception to indicate a failure, in this case it must not call the notifier again. It must throw an exception if the process has been cancelled. Anyways, I think I’ve got a correct implementation now 😅
(defn seed [coll]
(fn flow [notifier terminator]
(let [remaining (atom (seq coll))
cancelled (atom false)]
(if (empty? @remaining)
(terminator)
(notifier))
(reify
IFn
(invoke [iter] (reset! cancelled true))
IDeref
(deref [iter]
(let [retval (first @remaining)]
(swap! remaining rest)
(if (or (empty? @remaining) @cancelled)
(do (terminator)
(when @cancelled (throw (Cancelled. "Seed cancelled"))))
(notifier))
retval))))))
This missionary stuff is really heavy on my brain so sorry for confusing things 😅