Fork me on GitHub
#core-async
<
2018-12-03
>
pradyumna07:12:23

hi, i have a query about pub/sub. what happens to any message if they are not subscribed by any of them. Will they accumulate in the pub channel and prevent further put! Is there a best practice for using pub/sub?

souenzzo12:12:50

I think that it's a "global pattern" in clojure: if you will call a zero-arg function, example (UUID/randomUUID), or (async/chan), it's better to let it be a argument.

đź‘Ś 8
Alex Miller (Clojure team)14:12:11

@pradyumna this is covered in the docstring for pub: “Items received when there are no matching subs get dropped.”

gordon18:12:33

regarding returning a channel vs. passing one in, I've very often found myself returning channels when building async APIs. for example, those APIs look similar to Datomic Client's async API which do not provide (or need to provide, IMO) a way to pass a channel in: https://docs.datomic.com/client-api/datomic.client.api.async.html

orestis19:12:00

Is it different when your API is a “source” of values (e.g. from some external system) versus a “middleware”?

markmarkmark20:12:59

one piece of guidance I've seen from the Go people is that a function should accept a channel as an argument if it is going to be putting an unbounded amount of data over the channel.

markmarkmark20:12:07

and I wasn't really able to find much discussion about it

mpenet20:12:46

In clojure another argument for this is (among others) is that you can create the input chan with an xform (or useful buffer etc)

markmarkmark20:12:03

maybe a way to think of it is, pass a channel in if you would otherwise be passing in a callback/observer. pass a channel out if you would be returning a promise/future.

markmarkmark20:12:21

I'm not sure if that's a very useful distinction though

mpenet20:12:37

I tend to allow passing one via an opts, set a sane default if it's not supplied

orestis20:12:17

Yeah, many times channels are used to just return a single thing. I wonder if promise-chan is better served if you just want to model an async api?

mpenet20:12:21

For single val yes. I did that a few times with db clients

mpenet20:12:29

It's much more lightweight

mpenet20:12:36

And the fact takes return the same val can be handy

mpenet20:12:01

But even a promise-chan can take an xform, so it's still useful to let the user pass it as arg if possible imho