Class: Xlogin::SessionPool
- Inherits:
-
Object
- Object
- Xlogin::SessionPool
- Defined in:
- lib/xlogin/session_pool.rb
Constant Summary collapse
- DEFAULT_SIZE =
1- DEFAULT_IDLE =
false
Instance Method Summary collapse
- #idle ⇒ Object
-
#initialize(args, **opts) ⇒ SessionPool
constructor
A new instance of SessionPool.
- #size ⇒ Object
- #with ⇒ Object
Constructor Details
#initialize(args, **opts) ⇒ SessionPool
Returns a new instance of SessionPool.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/xlogin/session_pool.rb', line 10 def initialize(args, **opts) @args = args @opts = opts @mutex = Mutex.new @queue = Queue.new @created = 0 @watchdog = Hash.new end |
Instance Method Details
#idle ⇒ Object
28 29 30 31 32 33 |
# File 'lib/xlogin/session_pool.rb', line 28 def idle case @args when String then @opts[:idle] || DEFAULT_IDLE when Hash then @args[:idle] || DEFAULT_IDLE end end |
#size ⇒ Object
21 22 23 24 25 26 |
# File 'lib/xlogin/session_pool.rb', line 21 def size case @args when String then @opts[:size] || DEFAULT_SIZE when Hash then @args[:size] || DEFAULT_SIZE end end |
#with ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/xlogin/session_pool.rb', line 35 def with session = deq begin Thread.handle_interrupt(Exception => :immediate) { yield session } ensure enq(session) end end |