diff options
author | Dmitry Kim <dmitry point kim at gmail point com> | 2007-08-31 00:12:22 +0000 |
---|---|---|
committer | Dmitry Kim <dmitry point kim at gmail point com> | 2007-08-31 00:12:22 +0000 |
commit | 55a1893a1cb5a7872339f2280cc5927b97f16327 (patch) | |
tree | f60b4476fc786575e22e26dc4f774a2de6b07c5e | |
parent | 6fc49d16d7fc9c9b5c80bed4b095d2701fb01d90 (diff) |
* (timer) stop the bot timer for shutdown / rescan
-rw-r--r-- | lib/rbot/ircbot.rb | 5 | ||||
-rw-r--r-- | lib/rbot/timer.rb | 20 |
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? |