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)


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

Returns:

  • (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

#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