summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rbot/timer.rb30
1 files changed, 11 insertions, 19 deletions
diff --git a/lib/rbot/timer.rb b/lib/rbot/timer.rb
index 8adb14d8..f68e490a 100644
--- a/lib/rbot/timer.rb
+++ b/lib/rbot/timer.rb
@@ -233,31 +233,23 @@ class Timer
end
def run_actions(now = Time.now)
- nxt = nil
@actions.keys.each do |k|
return -1 if @stopping
- a = @actions[k]
- next if (!a) or a.blocked?
-
- if a.next <= now
- begin
- @current = k
- v = a.run(now)
- ensure
- @current = nil
- end
-
- unless v
- @actions.delete k
- next
- end
- else
- v = a.next
+ a = @actions[k] or next
+ next if a.blocked? || a.next > now
+
+ begin
+ @current = k
+ a.run(now)
+ ensure
+ @current = nil
end
- nxt = v if v and ((!nxt) or (v < nxt))
+ @actions.delete k unless a.next
end
+ nxt = @actions.values.map { |v| v.next }.min
+
if nxt
delta = nxt - now
delta = 0 if delta < 0