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:
parent
63fab09ea0
commit
9cfa89855d
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue