Class: Build::Graph::Edge
- Inherits:
-
Object
- Object
- Build::Graph::Edge
- Defined in:
- lib/build/graph/edge.rb
Overview
Represents a set of inputs to a graph node.
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#fiber ⇒ Object
readonly
Returns the value of attribute fiber.
Instance Method Summary collapse
- #failed? ⇒ Boolean
-
#increment! ⇒ Object
Increase the number of traversals we are waiting for.
-
#initialize(count = 0) ⇒ Edge
constructor
A new instance of Edge.
- #skip!(task) ⇒ Object
- #succeeded? ⇒ Boolean
-
#traverse(task) ⇒ Object
Traverse the edge, mark the edge as failed if the source was also failed.
-
#wait ⇒ Object
Wait until all inputs to the edge have been traversed.
Constructor Details
#initialize(count = 0) ⇒ Edge
Returns a new instance of Edge.
29 30 31 32 33 34 35 36 37 |
# File 'lib/build/graph/edge.rb', line 29 def initialize(count = 0) @fiber = Fiber.current # The number of inputs we are waiting for: @count = count @vertices = 0 @failed = [] end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
42 43 44 |
# File 'lib/build/graph/edge.rb', line 42 def count @count end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
39 40 41 |
# File 'lib/build/graph/edge.rb', line 39 def failed @failed end |
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
41 42 43 |
# File 'lib/build/graph/edge.rb', line 41 def fiber @fiber end |
Instance Method Details
#failed? ⇒ Boolean
55 56 57 |
# File 'lib/build/graph/edge.rb', line 55 def failed? @failed.size != 0 end |
#increment! ⇒ Object
Increase the number of traversals we are waiting for.
86 87 88 89 |
# File 'lib/build/graph/edge.rb', line 86 def increment! @vertices += 1 @count += 1 end |
#skip!(task) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/build/graph/edge.rb', line 77 def skip!(task) @vertices += 1 if task.failed? @failed << task end end |
#succeeded? ⇒ Boolean
59 60 61 |
# File 'lib/build/graph/edge.rb', line 59 def succeeded? @failed.size == 0 end |
#traverse(task) ⇒ Object
Traverse the edge, mark the edge as failed if the source was also failed.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/build/graph/edge.rb', line 64 def traverse(task) @count -= 1 # The entire edge fails if any individual task fails. if task.failed? @failed << task end if @count == 0 @fiber.resume end end |
#wait ⇒ Object
Wait until all inputs to the edge have been traversed. Returns false if failed?
45 46 47 48 49 50 51 |
# File 'lib/build/graph/edge.rb', line 45 def wait if @count > 0 Fiber.yield end succeeded? end |