Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: API to reach registered events and errors upon non-existing subscription #3

Open
mensfeld opened this issue Feb 27, 2018 · 0 comments

Comments

@mensfeld
Copy link
Collaborator

Moved from here: dry-rb/dry-monitor#11

Hey guys,

We use dry-monitor together with dry-events in karafka. In order to provide a "safe" API (safe in terms of typo mistakes etc) we've implemented two additional methods for the monitor that could be useful when working with it. Would it fit as a PR in this library?

      # Allows us to subscribe to events with a code that will be yielded upon events
      # @param event_name_or_listener [String, Object] name of the event we want to subscribe to
      #   or a listener if we decide to go with object listener
      def subscribe(event_name_or_listener)
        return super unless event_name_or_listener.is_a?(String)
        return super if available_events.include?(event_name_or_listener)
        raise Errors::UnregisteredMonitorEvent, event_name_or_listener
      end

      # @return [Array<String>] names of available events to which we can subscribe
      def available_events
        __bus__.events.keys
      end

I believe that this behavior would prevent users from subscribing to non-registered events.

Whole monitor can be found here: https://github.com/karafka/karafka/blob/master/lib/karafka/instrumentation/monitor.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants