lib/celluloid/receivers.rb in celluloid-0.16.0.pre2 vs lib/celluloid/receivers.rb in celluloid-0.16.0.pre3
- old
+ new
@@ -3,13 +3,13 @@
require 'timers'
module Celluloid
# Allow methods to directly interact with the actor protocol
class Receivers
- def initialize
+ def initialize(timers)
@receivers = Set.new
- @timers = Timers::Group.new
+ @timers = timers
end
# Receive an asynchronous message
def receive(timeout = nil, &block)
if Celluloid.exclusive?
@@ -27,26 +27,16 @@
@receivers << receiver
Task.suspend :receiving
end
end
- # How long to wait until the next timer fires
- def wait_interval
- @timers.wait_interval
- end
-
- # Fire any pending timers
- def fire_timers
- @timers.fire
- end
-
# Handle incoming messages
def handle_message(message)
receiver = @receivers.find { |r| r.match(message) }
return unless receiver
@receivers.delete receiver
- @timers.cancel receiver.timer if receiver.timer
+ receiver.timer.cancel if receiver.timer
receiver.resume message
message
end
end