# really short duration timers can overrun and leave @in negative,
# for these we set @in to @period
@in = @period if @in <= 0
- if(@data)
- @func.call(@data)
- else
- @func.call
+ begin
+ if(@data)
+ @func.call(@data)
+ else
+ @func.call
+ end
+ rescue Exception => e
+ error "Timer action #{self.inspect} with function #{@func.inspect} failed!"
+ error e.pretty_inspect
+ # TODO maybe we want to block this Action?
end
return @once
end
# reschedule the Action to change its period
def reschedule(new_period)
@period = new_period
+ @in = new_period
end
end
# block action with handle +handle+
def block(handle)
+ raise "no such timer #{handle}" unless @timers[handle]
@timers[handle].blocked = true
end
# unblock action with handle +handle+
def unblock(handle)
+ raise "no such timer #{handle}" unless @timers[handle]
@timers[handle].blocked = false
end
# reschedule action with handle +handle+ to change its period
def reschedule(handle, period)
+ raise "no such timer #{handle}" unless @timers[handle]
@timers[handle].reschedule(period)
end