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

Returns a new instance of Resource.



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

def initialize(concurrency = 1)
	@concurrency = concurrency
	@closed = false
	@count = 0
end

Instance Attribute Details

#concurrencyObject (readonly)



42
43
44
# File 'lib/async/pool/resource.rb', line 42

def concurrency
  @concurrency
end

#countObject (readonly)



45
46
47
# File 'lib/async/pool/resource.rb', line 45

def count
  @count
end

Class Method Details

.callObject

Constructs a resource.



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

def self.call
	self.new
end

Instance Method Details

#closeObject

Close the resource explicitly, e.g. the pool is being closed.



60
61
62
# File 'lib/async/pool/resource.rb', line 60

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.



55
56
57
# File 'lib/async/pool/resource.rb', line 55

def closed?
	@closed
end

#reusable?Boolean

Whether this resource can be reused. Used when releasing resources back into the pool.

Returns:

  • (Boolean)


65
66
67
# File 'lib/async/pool/resource.rb', line 65

def reusable?
	!@closed
end

#viable?Boolean

Whether this resource can be acquired.

Returns:

  • (Boolean)

    whether the resource can actually be used.



49
50
51
# File 'lib/async/pool/resource.rb', line 49

def viable?
	!@closed
end