Class: Build::Graph::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/build/graph/edge.rb

Overview

Represents a set of inputs to a graph node.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject (readonly)

Returns the value of attribute count.



42
43
44
# File 'lib/build/graph/edge.rb', line 42

def count
  @count
end

#failedObject (readonly)

Returns the value of attribute failed.



39
40
41
# File 'lib/build/graph/edge.rb', line 39

def failed
  @failed
end

#fiberObject (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

Returns:

  • (Boolean)


53
54
55
# File 'lib/build/graph/edge.rb', line 53

def failed?
  @failed.size != 0
end

#increment!Object

Increase the number of traversals we are waiting for.



84
85
86
87
# File 'lib/build/graph/edge.rb', line 84

def increment!
  @vertices += 1
  @count += 1
end

#skip!(task) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/build/graph/edge.rb', line 75

def skip!(task)
  @vertices += 1
  
  if task.failed?
    @failed << task
  end
end

#succeeded?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/build/graph/edge.rb', line 57

def succeeded?
  @failed.size == 0
end

#traverse(task) ⇒ Object

Traverse the edge, mark the edge as failed if the source was also failed.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/build/graph/edge.rb', line 62

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

#waitObject

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