Class: Async::Pool::Resource
- Inherits:
-
Object
- Object
- Async::Pool::Resource
- Defined in:
- lib/async/pool/resource.rb
Overview
The basic interface required by a pool resource.
Instance Attribute Summary collapse
- #concurrency ⇒ Object readonly
- #count ⇒ Object readonly
Class Method Summary collapse
-
.call ⇒ Object
Constructs a resource.
Instance Method Summary collapse
-
#close ⇒ Object
Close the resource explicitly, e.g.
-
#closed? ⇒ Boolean
Whether the resource has been closed by the user.
-
#initialize(concurrency = 1) ⇒ Resource
constructor
Create a new resource.
-
#reusable? ⇒ Boolean
Whether this resource can be reused.
-
#viable? ⇒ Boolean
Whether this resource can be acquired.
Constructor Details
#initialize(concurrency = 1) ⇒ Resource
Create a new resource.
23 24 25 26 27 |
# File 'lib/async/pool/resource.rb', line 23 def initialize(concurrency = 1) @concurrency = concurrency @closed = false @count = 0 end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
30 31 32 |
# File 'lib/async/pool/resource.rb', line 30 def concurrency @concurrency end |
#count ⇒ Object (readonly)
33 34 35 |
# File 'lib/async/pool/resource.rb', line 33 def count @count end |
Class Method Details
.call ⇒ Object
Constructs a resource.
16 17 18 |
# File 'lib/async/pool/resource.rb', line 16 def self.call self.new end |
Instance Method Details
#close ⇒ Object
Close the resource explicitly, e.g. the pool is being closed.
48 49 50 |
# File 'lib/async/pool/resource.rb', line 48 def close @closed = true end |
#closed? ⇒ Boolean
Whether the resource has been closed by the user.
43 44 45 |
# File 'lib/async/pool/resource.rb', line 43 def closed? @closed end |
#reusable? ⇒ Boolean
Whether this resource can be reused. Used when releasing resources back into the pool.
53 54 55 |
# File 'lib/async/pool/resource.rb', line 53 def reusable? !@closed end |
#viable? ⇒ Boolean
Whether this resource can be acquired.
37 38 39 |
# File 'lib/async/pool/resource.rb', line 37 def viable? !@closed end |