How not to drop core.async publication items?

83 views
Skip to first unread message

Cristian C

unread,
Feb 24, 2015, 4:51:41 PM2/24/15
to clo...@googlegroups.com
My test case would be something like this:

;; I have a channel that I want to wrap in a publication
(def publisher (async/chan))
(def publication (async/pub publisher :topic))

;; then I put data into the publisher channel
(async/put! publisher {:topic :foo :payload "first message"})

;; then I create a channel to read data from that publication
(def reader (async/chan))
(async/sub publication :foo reader)
(async/go (println "value is: " (async/<! reader)))

;; nothing happens since the publication already read the value and dropped it

;; if I send another message, this time it will be read by the <! above
(async/put! c1 {:topic :foo :msg "second message"})
==> value is {:topic :foo :msg "second message"}


Is there a way not to lose that first item?

Leon Grapenthin

unread,
Feb 25, 2015, 2:03:19 PM2/25/15
to clo...@googlegroups.com
Docstring says "Items received when there are no matching subs get dropped."

You would have to implement your own version of the Pub interface which caches all messages and broadcasts them all to a newly subscribed channel within sub.

Notice that an unlimited cache would imply a possible memory leak.

It is highly questionable whether this solution is a good fit for the underlying problem you are trying to solve. It is more likely that it would solve a problem resulting from a synchronization problem which should be solved elsewhere.
Reply all
Reply to author
Forward
0 new messages