class Celluloid::Mailbox::Evented
An alternative implementation of Celluloid::Mailbox using Reactor
Attributes
reactor[R]
Public Class Methods
new(reactor_class)
click to toggle source
Calls superclass method
Celluloid::Mailbox.new
# File lib/celluloid/mailbox/evented.rb, line 7 def initialize(reactor_class) super() # @condition won't be used in the class. @reactor = reactor_class.new end
Public Instance Methods
<<(message)
click to toggle source
Add a message to the Mailbox
# File lib/celluloid/mailbox/evented.rb, line 14 def <<(message) @mutex.lock begin if mailbox_full || @dead dead_letter(message) return end if message.is_a?(SystemEvent) # SystemEvents are high priority messages so they get added to the # head of our message queue instead of the end @messages.unshift message else @messages << message end ensure @mutex.unlock rescue nil end begin current_actor = Thread.current[:celluloid_actor] @reactor.wakeup unless current_actor && current_actor.mailbox == self rescue Internals::Logger.crash "reactor crashed", $ERROR_INFO dead_letter(message) end nil end
check(timeout = nil, &block)
click to toggle source
Receive a message from the Mailbox
# File lib/celluloid/mailbox/evented.rb, line 42 def check(timeout = nil, &block) # Get a message if it is available and process it immediately if possible: if message = next_message(block) return message end # ... otherwise, run the reactor once, either blocking or will return # after the given timeout: @reactor.run_once(timeout) # No message was received: return nil end
next_message(block)
click to toggle source
Obtain the next message from the mailbox that matches the given block
Calls superclass method
Celluloid::Mailbox#next_message
# File lib/celluloid/mailbox/evented.rb, line 57 def next_message(block) @mutex.lock begin super(&block) ensure @mutex.unlock rescue nil end end
shutdown()
click to toggle source
Cleanup any IO objects this Mailbox may be using
Calls superclass method
Celluloid::Mailbox#shutdown
# File lib/celluloid/mailbox/evented.rb, line 67 def shutdown super do @reactor.shutdown end end