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
This is called in the case that a parent fails to complete because a child task has failed.
- #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.
27 28 29 30 31 32 33 34 35 |
# File 'lib/build/graph/edge.rb', line 27 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.
40 41 42 |
# File 'lib/build/graph/edge.rb', line 40 def count @count end |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
37 38 39 |
# File 'lib/build/graph/edge.rb', line 37 def failed @failed end |
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
39 40 41 |
# File 'lib/build/graph/edge.rb', line 39 def fiber @fiber end |
Instance Method Details
#failed? ⇒ Boolean
51 52 53 |
# File 'lib/build/graph/edge.rb', line 51 def failed? @failed.size != 0 end |
#increment! ⇒ Object
Increase the number of traversals we are waiting for.
83 84 85 86 |
# File 'lib/build/graph/edge.rb', line 83 def increment! @vertices += 1 @count += 1 end |
#skip!(task) ⇒ Object
This is called in the case that a parent fails to complete because a child task has failed.
74 75 76 77 78 79 80 |
# File 'lib/build/graph/edge.rb', line 74 def skip!(task) @vertices += 1 if task.failed? @failed << task end end |
#succeeded? ⇒ Boolean
55 56 57 |
# File 'lib/build/graph/edge.rb', line 55 def succeeded? @failed.size == 0 end |
#traverse(task) ⇒ Object
Traverse the edge, mark the edge as failed if the source was also failed.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/build/graph/edge.rb', line 60 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?
43 44 45 46 47 48 49 |
# File 'lib/build/graph/edge.rb', line 43 def wait if @count > 0 Fiber.yield end succeeded? end |