-require 'fileutils'
module Redwood
-class SuicideException < StandardError; end
-
class SuicideManager
include Singleton
def initialize fn
@fn = fn
+ @die = false
+ @thread = nil
self.class.i_am_the_instance self
+ FileUtils.rm_f @fn
end
- def start_thread
- Redwood::reporting_thread do
+ bool_reader :die
+
+ def start
+ @thread = Redwood::reporting_thread("suicide watch") do
while true
sleep DELAY
if File.exists? @fn
- FileUtils.rm_rf @fn
- raise SuicideException
+ FileUtils.rm_f @fn
+ @die = true
end
end
end
end
+
+ def stop
+ @thread.kill if @thread
+ @thread = nil
+ end
end
end