Ensure busy turns to false when an exception is raised, rather than catching the exception. Moved the ensure within the synchronize block so its protected by the mutex.

This commit is contained in:
Mitchell Hashimoto 2010-02-08 23:32:04 -08:00
parent 63fab09ea0
commit 9cfa89855d
1 changed files with 9 additions and 9 deletions

View File

@ -10,6 +10,7 @@ module Hobo
class Busy class Busy
@@busy = false @@busy = false
@@mutex = Mutex.new @@mutex = Mutex.new
class << self class << self
def busy? def busy?
@@busy @@busy
@ -21,16 +22,15 @@ module Hobo
def busy(&block) def busy(&block)
@@mutex.synchronize do @@mutex.synchronize do
Busy.busy = true begin
yield Busy.busy = true
Busy.busy = false 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
# In the case were an exception is thrown by the wrapped code
# make sure to set busy to sane state and reraise the error
rescue Exception => e
Busy.busy = false
raise
end end
end end
end end