Class: Debtor
- Inherits:
-
Object
- Object
- Debtor
- Defined in:
- lib/arboretum/debtor.rb
Instance Method Summary collapse
- #free ⇒ Object
- #free? ⇒ Boolean
-
#initialize ⇒ Debtor
constructor
A new instance of Debtor.
- #locked? ⇒ Boolean
- #resource ⇒ Object
- #resource! ⇒ Object
- #set_resource(rsc) ⇒ Object (also: #set)
Constructor Details
#initialize ⇒ Debtor
Returns a new instance of Debtor.
15 16 17 18 19 |
# File 'lib/arboretum/debtor.rb', line 15 def initialize @resource = nil @locked = true @creditors = Array.new end |
Instance Method Details
#free ⇒ Object
44 45 46 47 48 |
# File 'lib/arboretum/debtor.rb', line 44 def free @locked = false @creditors.each {|c| c.resume } @creditors = Array.new end |
#free? ⇒ Boolean
41 42 43 |
# File 'lib/arboretum/debtor.rb', line 41 def free? !@locked end |
#locked? ⇒ Boolean
38 39 40 |
# File 'lib/arboretum/debtor.rb', line 38 def locked? @locked end |
#resource ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/arboretum/debtor.rb', line 24 def resource begin if locked? @creditors << Fiber.current Fiber.yield end rescue FiberError puts "Warning: Tried to yield the root Fiber on a locked resource call. Returning resource anyways..." end @resource end |
#resource! ⇒ Object
35 36 37 |
# File 'lib/arboretum/debtor.rb', line 35 def resource! @resource end |
#set_resource(rsc) ⇒ Object Also known as: set
20 21 22 |
# File 'lib/arboretum/debtor.rb', line 20 def set_resource(rsc) @resource = rsc end |