class Celluloid::Notifications::Fanout - celluloid-0.16.0 Documentation

# class Celluloid::Notifications::Fanout

### Public Class Methods

new() click to toggle source

    # File lib/celluloid/notifications.rb, line 23
    def initialize
      @subscribers = []
      @listeners_for = {}
    end

### Public Instance Methods

listeners_for(pattern) click to toggle source

    # File lib/celluloid/notifications.rb, line 46
    def listeners_for(pattern)
      @listeners_for[pattern] ||= @subscribers.select { |s| s.subscribed_to?(pattern) }
    end

listening?(pattern) click to toggle source

    # File lib/celluloid/notifications.rb, line 50
    def listening?(pattern)
      listeners_for(pattern).any?
    end

prune(actor, reason=nil) click to toggle source

    # File lib/celluloid/notifications.rb, line 54
    def prune(actor, reason=nil)
      @subscribers.reject! { |s| s.actor == actor }
      @listeners_for.clear
    end

publish(pattern, *args) click to toggle source

    # File lib/celluloid/notifications.rb, line 42
    def publish(pattern, *args)
      listeners_for(pattern).each { |s| s.publish(pattern, *args) }
    end

subscribe(actor, pattern, method) click to toggle source

    # File lib/celluloid/notifications.rb, line 28
    def subscribe(actor, pattern, method)
      subscriber = Subscriber.new(actor, pattern, method).tap do |s|
        @subscribers << s
      end
      link actor
      @listeners_for.clear
      subscriber
    end

unsubscribe(subscriber) click to toggle source

    # File lib/celluloid/notifications.rb, line 37
    def unsubscribe(subscriber)
      @subscribers.reject! { |s| s.matches?(subscriber) }
      @listeners_for.clear
    end