celluloid/celluloid — pull request #450 by ioquatix (2014-07-17 14:05:54+00:00)
Title: Fix every timers

Fixes https://github.com/celluloid/celluloid/issues/443

I am concerned about changing `Mailbox#receive(interval)` to a method that may return nil and return before the interval is up, although when I thought about similar APIs, e.g. select(..., interval), it is actually a reasonable behaviour. My concern stems from places where the message is expected to be non-nil.

e.g.

lib/celluloid/calls.rb

def wait
loop do
message = Celluloid.mailbox.receive do |msg|
msg.respond_to?(:call) and msg.call == self
end

if message.is_a?(SystemEvent)
Thread.current[:celluloid_actor].handle_system_event(message)
else
# FIXME: add check for receiver block execution
if message.respond_to?(:value)
# FIXME: disable block execution if on :sender and (exclusive or outside of task)
# probably now in Call
break message
else
message.dispatch
end
end
end
end

The best option, IMHO, is to review all instances of Mailbox#receive and look at the logic of the caller for a start to try and understand the ways in which it is being used.

As an example, the above code expects a message of a certain type and passes a filtering block. In this case that a block is provided, perhaps we could change the behaviour of Mailbox#receive to loop until a message was received that met the criteria.

Also the above code looks like a bit of a hack (e.g. the handling of system events). If this is a common use case why not put the functionality directly into Actor.

Anyway, I believe this is a reasonable patch and fixes the bug but the implications of the fix need to be discussed.