clj-commons / manifold

A compatibility layer for event-driven abstractions
1.02k stars 108 forks source link

add `hasActive` method to IEventBus #45

Closed dm3 closed 9 years ago

dm3 commented 9 years ago

Sometimes it's valuable to know if there are any subscribers on the bus at all. Currently the subscription map on the bus isn't exposed in any way, so it's impossible without knowing all of the topics.

Please consider adding either something like hasActive or a way to access the underlying subscription store.

ztellman commented 9 years ago

I think I'd prefer to either expose a list of the topics, or just return the map of topics onto subscriber streams. Can you explain your use case so I can better understand what you're trying to accomplish?

dm3 commented 9 years ago

In my case I have a stream of notifications which are processed and fed into the bus. A notification only needs to be processed if there are subscribers on the bus, else it's skipped. I must say I'm abusing the bus a bit as the subscription logic doesn't map directly to topics. However all the other subscription housekeeping machinery of the bus is useful.

ztellman commented 9 years ago

Why not just have a hard coded topic and check whether it's active, then?

On Tue, Jul 28, 2015, 2:00 PM Vadim Platonov notifications@github.com wrote:

In my case I have a stream of notifications which are processed and fed into the bus. A notification only needs to be processed if there are subscribers on the bus, else it's skipped. I must say I'm abusing the bus a bit as the subscription logic doesn't map directly to topics. However all the other subscription housekeeping machinery of the bus is useful.

— Reply to this email directly or view it on GitHub https://github.com/ztellman/manifold/pull/45#issuecomment-125752586.

dm3 commented 9 years ago

That's actually solves my case! I can see how this might resurface, e.g. if I had topics dynamically derived from notifications and not just a bunch of hardcoded ones.

Your call on closing/updating this PR. I'm happy with either choice.

ztellman commented 9 years ago

I'll close it, but will look into something that gives more visibility than the current methods.

dm3 commented 9 years ago

Thanks for your time! Another feature that I've come up with for the bus is being able to close it. When the component that owns the bus is being shut down, I want to close all the subscriptions. I have a hunch this is a valid feature request, but I might be abusing the thing again :)