]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/timer.rb
Output gettext textdomain information when setting the language, not when loading...
[user/henk/code/ruby/rbot.git] / lib / rbot / timer.rb
index 0527c1e782e19578c8565a4f8c38be4d2f7807d8..db0c6ea16bee0d89aefd0104832347551fee997c 100644 (file)
@@ -45,10 +45,16 @@ module Timer
       # 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
@@ -56,6 +62,7 @@ module Timer
     # reschedule the Action to change its period
     def reschedule(new_period)
       @period = new_period
+      @in = new_period
     end
   end
 
@@ -110,16 +117,19 @@ module Timer
 
     # 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