core-async

2022-08-15T18:31:56.629869Z

If I want one way communicate between two threads. Is there any reason to use core.async channels over an atom containing a PersistentQueue?

2022-08-15T18:34:26.244319Z

it depends, but a pq in an atom has some annoying ergonomics (you need to remove two operations to dequeue something, peek then pop, squaring that with atoms is doable, but annoying)

2022-08-15T18:35:36.427119Z

pqs in an atom also are not blocking, you can't have your thread stop until a new item is added

2022-08-15T18:36:32.069629Z

if you just don't want to pull in core.async, java.util.concurrent comes with a variety of useful queues, I usually start with a java.util.concurrent.LinkedBlockingQueue

👀 1
2022-08-15T18:39:06.740759Z

Ahh didn’t think about the non blocking part. Thanks for the java.util.concurrent.LinkedBlockingQueue suggestion. Was just wondering wether using core.async only for channels wasn’t a bit overkill.

2022-08-15T18:39:22.407169Z

a https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/SynchronousQueue.html is sort of like a core.async channel with no buffer

2022-08-15T18:40:07.827389Z

a feature that channels have that is hard to replicate with java queues is closing

2022-08-15T18:41:43.358679Z

another feature is alts (no-deterministic choice over a collection of reads and writes)

Alex Miller (Clojure team) 2022-08-15T18:49:59.179479Z

LinkedTransferQueue is like a channel with a buffer

👀 2
2022-08-15T19:00:24.272979Z

I’ll give LinkedTransferQueue a try (as that seems to be exactly what I was looking for). Though it sound like using core.async might save me some pain in the long run. I just wasn’t particularly needing the asynchronous part.

2022-08-15T19:00:47.830659Z

Thank you both for your help!