class Async::Node
Represents a node in a tree, used for nested {Task} instances.
def consume
If the node has a parent, and is {finished?}, then remove this node from
def consume if @parent && finished? @parent.reap(self) @parent.consume @parent = nil end end
def finished?
-
(Boolean)
-
def finished? @children.empty? end
def initialize(parent = nil)
-
parent
(Node, nil
) -- This node will attach to the given parent.
def initialize(parent = nil) @children = Set.new @parent = nil if parent self.parent = parent end end
def parent=(parent)
-
(self)
-
Parameters:
-
parent
(Node, nil
) -- the parent to attach to, or nil to detach.
def parent=(parent) return if @parent.equal?(parent) if @parent @parent.reap(self) @parent = nil end if parent @parent = parent @parent.children << self end return self end
def reap(child)
-
child
(Node
) --
def reap(child) @children.delete(child) end