Class: Innertube::Pool::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/innertube.rb

Overview

An element of the pool. Comprises an object with an owning thread. Not usually needed by user code, and should not be modified outside the Innertube::Pool's lock.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Element

Creates a pool element

Parameters:

  • object (Object)

    the resource to wrap into the pool element


24
25
26
27
# File 'lib/innertube.rb', line 24

def initialize(object)
  @object = object
  @owner = nil
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object


20
21
22
# File 'lib/innertube.rb', line 20

def object
  @object
end

#ownerObject (readonly)

Returns the value of attribute owner


20
21
22
# File 'lib/innertube.rb', line 20

def owner
  @owner
end

Instance Method Details

#lockObject

Claims this element of the pool for the current Thread. Do not call this manually, it is only used from inside the pool.


31
32
33
# File 'lib/innertube.rb', line 31

def lock
  @owner = Thread.current
end

#locked?true, false

Returns Is this element locked/claimed?.

Returns:

  • (true, false)

    Is this element locked/claimed?


36
37
38
# File 'lib/innertube.rb', line 36

def locked?
  !unlocked?
end

#unlockObject

Releases this element of the pool from the current Thread.


41
42
43
# File 'lib/innertube.rb', line 41

def unlock
  @owner = nil
end

#unlocked?true, false

Returns Is this element available for use?.

Returns:

  • (true, false)

    Is this element available for use?


46
47
48
# File 'lib/innertube.rb', line 46

def unlocked?
  owner.nil?
end