Class: Celluloid::Internals::Receivers
- Inherits:
-
Object
- Object
- Celluloid::Internals::Receivers
- Defined in:
- lib/celluloid/internals/receivers.rb
Overview
Allow methods to directly interact with the actor protocol
Instance Method Summary collapse
-
#handle_message(message) ⇒ Object
Handle incoming messages.
-
#initialize(timers) ⇒ Receivers
constructor
A new instance of Receivers.
-
#receive(timeout = nil, &block) ⇒ Object
Receive an asynchronous message.
Constructor Details
#initialize(timers) ⇒ Receivers
Returns a new instance of Receivers.
8 9 10 11 |
# File 'lib/celluloid/internals/receivers.rb', line 8 def initialize(timers) @receivers = Set.new @timers = timers end |
Instance Method Details
#handle_message(message) ⇒ Object
Handle incoming messages
33 34 35 36 37 38 39 40 41 |
# File 'lib/celluloid/internals/receivers.rb', line 33 def () receiver = @receivers.find { |r| r.match() } return unless receiver @receivers.delete receiver receiver.timer.cancel if receiver.timer receiver.resume end |
#receive(timeout = nil, &block) ⇒ Object
Receive an asynchronous message
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/celluloid/internals/receivers.rb', line 14 def receive(timeout = nil, &block) if Celluloid.exclusive? Celluloid.mailbox.receive(timeout, &block) else receiver = Receiver.new block if timeout receiver.timer = @timers.after(timeout) do @receivers.delete receiver receiver.resume end end @receivers << receiver Task.suspend :receiving end end |