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
@@busy = false
@@mutex = Mutex.new
class << self
def busy?
@@busy
@ -21,16 +22,15 @@ module Hobo
def busy(&block)
@@mutex.synchronize do
Busy.busy = true
yield
Busy.busy = false
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
# 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