vaguerent/lib/hobo/busy.rb
Mitchell Hashimoto dccfeafa2e Revert "changed rescue to ensure block in Busy.busy"
Tests ensure that the ensure block within the mutex handles setting busy to false in the case of an exception.
2010-02-09 09:30:40 -08:00

38 lines
607 B
Ruby

module Hobo
def self.busy?
Busy.busy?
end
def self.busy(&block)
Busy.busy(&block)
end
class Busy
@@busy = false
@@mutex = Mutex.new
class << self
def busy?
@@busy
end
def busy=(val)
@@busy = val
end
def busy(&block)
@@mutex.synchronize do
begin
Busy.busy = true
yield
ensure
# In the case an exception is thrown, make sure we restore
# busy back to some sane state.
Busy.busy = false
end
end
end
end
end
end