lib/eventable/eventable.rb
def fire_event(event, *return_value, &block)
    check_mutex
    @eventable_mutex.synchronize {

      return false unless @callbacks && @callbacks[event] && !@callbacks[event].empty?

      @callbacks[event].each do |listener_id, callbacks|
        begin
          listener = ObjectSpace._id2ref(listener_id)
          callbacks.each do |callback|
            Thread.new {listener.send callback, *return_value, &block}
          end
        rescue RangeError => re
          # Don't bubble up a missing recycled object, I don't care if it's not there, I just won't call it
          raise re unless re.message.match(/is recycled object/)
        end
      end
    }
    true
  end
# When the event happens the class where it happens runs this
When the event happens the class where it happens runs this
When the event happens the class where it happens runs this
def fire_event(event, *return_value, &block)
    check_mutex
    @eventable_mutex.synchronize {
      return false unless @callbacks && @callbacks[event] && !@callbacks[event].empty?
      @callbacks[event].each do |listener_id, callbacks|
        begin
          listener = ObjectSpace._id2ref(listener_id)
          callbacks.each do |callback|
            Thread.new {listener.send callback, *return_value, &block}
          end
        rescue RangeError => re
          raise re unless re.message.match(/is recycled object/)
        end
      end
    }
    true
  end
def fire_event ( event , * return_value , & block ) check_mutex @eventable_mutex . synchronize { return false unless @callbacks && @callbacks [ event ] && ! @callbacks [ event ] . empty? @callbacks [ event ] . each do | listener_id , callbacks | begin listener = ObjectSpace . _id2ref ( listener_id ) callbacks . each do | callback | Thread . new { listener . send callback , * return_value , & block } end rescue RangeError => re raise re unless re . message . match ( / is recycled object / ) end end } true end
When the event happens the class where it happens runs this
When the event happens the class where it happens runs this
# Don't bubble up a missing recycled object, I don't care if it's not there, I just won't call it
event
return_value
block