From 9cfa89855dde7902734355da8d4323f0f4cce8d3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Feb 2010 23:32:04 -0800 Subject: [PATCH] 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. --- lib/hobo/busy.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/hobo/busy.rb b/lib/hobo/busy.rb index 309dbb4e6..0ac41c00e 100644 --- a/lib/hobo/busy.rb +++ b/lib/hobo/busy.rb @@ -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