taoensso / carmine

Redis client + message queue for Clojure
https://www.taoensso.com/carmine
Eclipse Public License 1.0
1.15k stars 131 forks source link

Allow `subscribe` and `psubscribe` to return a core.async channel #128

Closed glittershark closed 9 years ago

glittershark commented 9 years ago

I don't know if this isn't generic enough for carmine, but now that I'm up and running I've been thinking about how cool it would be to have an option, arity, whatever to subscribe and psubscribe to make them return a core.async channel that could be take!n from. Thoughts?

ptaoussanis commented 9 years ago

Hi Griffin,

I'd suggest that the correct (+ idiomatic) way of doing this is just to use the current Carmine callback mechanism to put! vals to your own core.async channel. I.e. your callback handler will just shuttle vals into your own core.async channel.

Advantages of this approach:

  1. No core.async dependency for folks that don't want it.
  2. No perf or conceptual overhead for folks that don't need it.
  3. The ability to choose + fully control your core.async channel and how you're using it, if you do want one.
  4. The ability to use an alternative data-flow model (i.e. something besides core.async) if the need somehow arises there.

So regular old callbacks turn out to be the right tool for the job here IMO. Plugging them into your own core.async (or alternative) system to coordinate higher-level data flow is super easy if that's what you want (I often do).

Does that make sense? :-)

glittershark commented 9 years ago

yeah, I'm totally with you on that - always good to keep OSS libs as generic, distinct, and isolated as possible. Thanks for the thorough, well thought-out response! Several :+1: for you. :grinning:

ptaoussanis commented 9 years ago

No problem, cheers :-)