lib/vx/consumer/session.rb in vx-consumer-0.0.2 vs lib/vx/consumer/session.rb in vx-consumer-0.1.0
- old
+ new
@@ -5,23 +5,37 @@
module Consumer
class Session
include Instrument
- @@session_lock = Mutex.new
+ @@session_lock = Mutex.new
+ @@shutdown_lock = Mutex.new
+ @@shutdown = ConditionVariable.new
+ @@live = false
+
attr_reader :conn
def shutdown
- @shutdown = true
+ @@shutdown_lock.synchronize do
+ @@live = false
+ @@shutdown.broadcast
+ end
end
- def shutdown?
- !!@shutdown
+ def live?
+ @@live
end
def resume
- @shutdown = false
+ @@live = true
+ end
+
+ def wait_shutdown(timeout = nil)
+ @@shutdown_lock.synchronize do
+ @@shutdown.wait(@@shutdown_lock, timeout)
+ not live?
+ end
end
def close
if open?
@@session_lock.synchronize do