lib/celluloid/actor.rb in celluloid-0.16.0.pre2 vs lib/celluloid/actor.rb in celluloid-0.16.0.pre3
- old
+ new
@@ -110,12 +110,12 @@
@exclusive = options.fetch(:exclusive, false)
@tasks = TaskSet.new
@links = Links.new
@signals = Signals.new
- @receivers = Receivers.new
@timers = Timers::Group.new
+ @receivers = Receivers.new(@timers)
@handlers = Handlers.new
@running = false
@name = nil
handle(SystemEvent) do |message|
@@ -145,15 +145,19 @@
# Run the actor loop
def run
while @running
begin
- message = @mailbox.receive(timeout_interval)
- handle_message message
- rescue TimeoutError
- @timers.fire
- @receivers.fire_timers
+ @timers.wait do |interval|
+ interval = 0 if interval and interval < 0
+
+ if message = @mailbox.check(interval)
+ handle_message(message)
+
+ break unless @running
+ end
+ end
rescue MailboxShutdown
@running = false
end
end
@@ -169,16 +173,14 @@
end
# Perform a linking request with another actor
def linking_request(receiver, type)
Celluloid.exclusive do
- linking_timeout = Timers::Timeout.new(LINKING_TIMEOUT)
-
receiver.mailbox << LinkingRequest.new(Actor.current, type)
system_events = []
- linking_timeout.while_time_remaining do |remaining|
+ Timers::Wait.for(LINKING_TIMEOUT) do |remaining|
begin
message = @mailbox.receive(remaining) do |msg|
msg.is_a?(LinkingResponse) &&
msg.actor.mailbox.address == receiver.mailbox.address &&
msg.type == type
@@ -224,23 +226,9 @@
loop do
message = @receivers.receive(timeout, &block)
break message unless message.is_a?(SystemEvent)
handle_system_event(message)
- end
- end
-
- # How long to wait until the next timer fires
- def timeout_interval
- i1 = @timers.wait_interval
- i2 = @receivers.wait_interval
-
- if i1 and i2
- i1 < i2 ? i1 : i2
- elsif i1
- i1
- else
- i2
end
end
# Schedule a block to run at the given time
def after(interval, &block)