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
# 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
  
  @failed = []
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



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

def count
  @count
end

#failedObject (readonly)

Returns the value of attribute failed.



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

def failed
  @failed
end

#fiberObject (readonly)

Returns the value of attribute fiber.



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

def fiber
  @fiber
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


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

def failed?
  @failed.size != 0
end

#increment!Object

Increase the number of traversals we are waiting for.



72
73
74
# File 'lib/build/graph/edge.rb', line 72

def increment!
  @count += 1
end

#traverse(node) ⇒ Object

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



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/build/graph/edge.rb', line 59

def traverse(node)
  @count -= 1

  if node.failed?
    @failed << node
  end

  if @count == 0
    @fiber.resume
  end
end

#waitObject

Wait until all inputs to the edge have been traversed.



44
45
46
47
48
49
50
# File 'lib/build/graph/edge.rb', line 44

def wait
  if @count > 0
    Fiber.yield
  end

  failed?
end