lib/celluloid/actor.rb in celluloid-0.15.0.pre2 vs lib/celluloid/actor.rb in celluloid-0.15.0

- old
+ new

@@ -266,9 +266,22 @@ # Schedule a block to run at the given time def every(interval, &block) @timers.every(interval) { task(:timer, &block) } end + def timeout(duration) + bt = caller + task = Task.current + timer = @timers.after(duration) do + exception = Task::TimeoutError.new("execution expired") + exception.set_backtrace bt + task.resume exception + end + yield + ensure + timer.cancel if timer + end + class Sleeper def initialize(timers, interval) @timers = timers @interval = interval end