]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/timer.rb
refactor: remove global bot instance, closes #42
[user/henk/code/ruby/rbot.git] / lib / rbot / timer.rb
index f68e490aefcd8a3a3711204208820655632c5549..64b0ee431d4aeb261541e43bda38f31dc9953770 100644 (file)
@@ -62,7 +62,7 @@ class Timer
       @repeat = opts[:repeat] if opts.include? :repeat
 
       if block_given?
-        @block = block 
+        @block = block
       elsif opts[:code]
         @block = opts[:code]
       end
@@ -214,7 +214,10 @@ class Timer
   end
 
   def stop
-    raise 'already stopped' unless @thread
+    unless @thread
+      warning 'trying to stop already stopped timer'
+      return
+    end
     debug "stopping timer #{self}..."
     @stopping = true
     self.synchronize { @tick.signal }
@@ -248,7 +251,7 @@ class Timer
       @actions.delete k unless a.next
     end
 
-    nxt = @actions.values.map { |v| v.next }.min
+    nxt = @actions.values.find_all { |v| !v.blocked? }.map{ |v| v.next }.min
 
     if nxt
       delta = nxt - now