summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rbot/ircbot.rb5
-rw-r--r--lib/rbot/timer.rb20
2 files changed, 22 insertions, 3 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 889daed0..46d5e902 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -1045,6 +1045,8 @@ class Bot
# end
debug "\tdisconnecting..."
disconnect(message)
+ debug "\tstopping timer..."
+ @timer.stop
debug "\tsaving ..."
save
debug "\tcleaning up ..."
@@ -1100,10 +1102,13 @@ class Bot
# call the rescan method for all of the botmodules
def rescan
+ debug "\tstopping timer..."
+ @timer.stop
@save_mutex.synchronize do
@lang.rescan
@plugins.rescan
end
+ @timer.start
end
# channel:: channel to join
diff --git a/lib/rbot/timer.rb b/lib/rbot/timer.rb
index 1802f9d2..10a6f318 100644
--- a/lib/rbot/timer.rb
+++ b/lib/rbot/timer.rb
@@ -198,18 +198,31 @@ class Timer
self.configure(aid, :period => period, &block)
end
- protected
-
def start
- raise 'double-started timer' if @thread
+ raise 'already started' if @thread
+ @stopping = false
+ debug "starting timer #{self}"
@thread = Thread.new do
loop do
tmout = self.run_actions
+ break if tmout and tmout < 0
self.synchronize { @tick.wait(tmout) }
end
end
end
+ def stop
+ raise 'already stopped' unless @thread
+ debug "stopping timer #{self}..."
+ @stopping = true
+ self.synchronize { @tick.signal }
+ @thread.join(60) or @thread.kill
+ debug "timer #{self} stopped"
+ @thread = nil
+ end
+
+ protected
+
def [](aid)
aid ||= @current
raise "no current action" unless aid
@@ -220,6 +233,7 @@ class Timer
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?