Class: Celluloid::Receivers
- Inherits:
-
Object
- Object
- Celluloid::Receivers
- Defined in:
- lib/celluloid/receivers.rb
Overview
Allow methods to directly interact with the actor protocol
Instance Method Summary collapse
-
#fire_timers ⇒ Object
Fire any pending timers.
-
#handle_message(message) ⇒ Object
Handle incoming messages.
-
#initialize ⇒ Receivers
constructor
A new instance of Receivers.
-
#receive(timeout = nil, &block) ⇒ Object
Receive an asynchronous message.
-
#wait_interval ⇒ Object
How long to wait until the next timer fires.
Constructor Details
Instance Method Details
#fire_timers ⇒ Object
Fire any pending timers
36 37 38 |
# File 'lib/celluloid/receivers.rb', line 36 def fire_timers @timers.fire end |
#handle_message(message) ⇒ Object
Handle incoming messages
41 42 43 44 45 46 47 48 |
# File 'lib/celluloid/receivers.rb', line 41 def () receiver = @receivers.find { |r| r.match() } return unless receiver @receivers.delete receiver @timers.cancel receiver.timer if receiver.timer receiver.resume end |
#receive(timeout = nil, &block) ⇒ Object
Receive an asynchronous message
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/celluloid/receivers.rb', line 12 def receive(timeout = nil, &block) if Celluloid.exclusive? Thread.mailbox.receive(timeout, &block) else receiver = Receiver.new block if timeout receiver.timer = @timers.add(timeout) do @receivers.delete receiver receiver.resume end end @receivers << receiver Task.suspend :receiving end end |
#wait_interval ⇒ Object
How long to wait until the next timer fires
31 32 33 |
# File 'lib/celluloid/receivers.rb', line 31 def wait_interval @timers.wait_interval end |