class Edge
Represents a set of inputs to a graph node.
Definitions
def initialize(count = 0)
Create a new edge, optionally pre-populated with a number of pending traversals.
Signature
-
parameter
countInteger the initial number of pending traversals.
Implementation
def initialize(count = 0)
@fiber = Fiber.current
# The number of inputs we are waiting for:
@count = count
@vertices = 0
@failed = []
end
def wait
Wait until all inputs to the edge have been traversed. Returns false if failed?
Implementation
def wait
if @count > 0
Fiber.yield
end
succeeded?
end
def failed?
Signature
-
returns
Boolean whether any traversing task failed.
Implementation
def failed?
@failed.size != 0
end
def succeeded?
Signature
-
returns
Boolean whether all traversing tasks succeeded.
Implementation
def succeeded?
@failed.size == 0
end
def traverse(task)
Traverse the edge, mark the edge as failed if the source was also failed.
Implementation
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
def skip!(task)
This is called in the case that a parent fails to complete because a child task has failed.
Implementation
def skip!(task)
@vertices += 1
if task.failed?
@failed << task
end
end
def increment!
Increase the number of traversals we are waiting for.
Implementation
def increment!
@vertices += 1
@count += 1
end