Permalink
Browse files

Update shutdown logic to use at_exit, not trap, per Eric Wong's advice.

Fix bug when shutting down with no queues.
  • Loading branch information...
1 parent 410cdac commit e4061ee1b4511cd7c76a796be513884068fbc058 @mperham committed May 3, 2011
Showing with 15 additions and 16 deletions.
  1. +15 −16 lib/girl_friday.rb
View
@@ -34,28 +34,27 @@ def self.shutdown!(timeout=30)
m = Mutex.new
var = ConditionVariable.new
- queues.each do |q|
- q.shutdown do |queue|
- m.synchronize do
- count -= 1
- var.signal if count == 0
+ if count > 0
+ queues.each do |q|
+ q.shutdown do |queue|
+ m.synchronize do
+ count -= 1
+ var.signal if count == 0
+ end
end
end
- end
- m.synchronize do
- var.wait(m, timeout)
+ m.synchronize do
+ var.wait(m, timeout)
+ end
+ #puts "girl_friday shutdown complete"
end
count
end
- ##
- # Hook girl_friday into your process shutdown logic.
- # Calls shutdown! on the given signal.
- def self.install_shutdown_hook(signal="QUIT")
- trap(signal) do
- GirlFriday.shutdown!
- end
- end
+end
+
+at_exit do
+ GirlFriday.shutdown!
end

0 comments on commit e4061ee

Please sign in to comment.