This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-31
Channels
- # announcements (1)
- # beginners (171)
- # cider (51)
- # clj-kondo (40)
- # cljsrn (5)
- # clojure (68)
- # clojure-dev (42)
- # clojure-europe (2)
- # clojure-italy (20)
- # clojure-spec (2)
- # clojure-uk (141)
- # clojurescript (19)
- # community-development (4)
- # core-async (17)
- # core-logic (3)
- # cursive (11)
- # data-science (1)
- # datomic (7)
- # defnpodcast (2)
- # figwheel (9)
- # figwheel-main (2)
- # fulcro (15)
- # graphql (21)
- # jackdaw (3)
- # joker (11)
- # juxt (1)
- # luminus (12)
- # off-topic (2)
- # pathom (73)
- # pedestal (2)
- # re-frame (41)
- # reagent (14)
- # reitit (4)
- # shadow-cljs (39)
- # tools-deps (4)
So I’ve implemented a bounded core async set buffer with an atom and a set, and it seems to work as I’d like:
My question is it seems core.async, checks channels test full?
before putting into the channel… However a few things have occured to me…
1. there’s a difference between the time you check full?
and the time you put!
into the channel… I’m assuming this isn’t a problem however because of the mutex inside the channels.
2. Given that there’s a mutex inside the channel, do I need to even use my atom here? Could I not get away with using a plain old java set instead?
the built in buffers just use plain data structures
Yes that’s what I’d noticed though they’re all java.util.LinkedList
s and I’d assumed they were getting away with using that because LinkedList’s are effectively persistent data structures anyway… Though I see that actually j.u.LinkedList is a double linked list, and not thread safe.
it's not thread safe
but the idea is that buffer manipulation is protected by the channel lock
yeah, this does mean in order to exert the backpressure via a 503 without blocking my request I need to also acquire that mutex with a try
finally
over (.. the-chan mutex lock)
Your buffer is unordered so you are losing the fifo queue behavior channels typically have
Yes I know. I don’t really require ordering, though I’ll maybe swap it to use a LinkedHashSet
to save anyone else using it any confusion.
You also wipe the buffer on close, which none of the built in buffers do, which means, I think, you won't be able to consume items that were inserted before the channel was closed
ahh thanks for clarifying, I wasn’t sure what the behaviour should be there; but makes a lot of sense
oh yes thanks for reminding me about offer!
I’d forgotten I discovered that yesterday :thumbsup: