Class: Async::Pool::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/async/pool/resource.rb

Overview

The basic interface required by a pool resource.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#concurrencyObject (readonly)



30
31
32
# File 'lib/async/pool/resource.rb', line 30

def concurrency
  @concurrency
end

#countObject (readonly)



33
34
35
# File 'lib/async/pool/resource.rb', line 33

def count
  @count
end

Class Method Details

.callObject

Constructs a resource.



16
17
18
# File 'lib/async/pool/resource.rb', line 16

def self.call
	self.new
end

Instance Method Details

#closeObject

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.

Returns:

  • (Boolean)

    whether the resource has been closed or has failed.



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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/async/pool/resource.rb', line 53

def reusable?
	!@closed
end

#viable?Boolean

Whether this resource can be acquired.

Returns:

  • (Boolean)

    whether the resource can actually be used.



37
38
39
# File 'lib/async/pool/resource.rb', line 37

def viable?
	!@closed
end