protected function detectLoop($parent, $child)
    {
        if ($child->name === $parent->name) {
            return reject(true);
        }

        return $this->getChildren($child->name)
            ->then(function($children) use ($parent) {
                $promises = [];
                foreach ($children as $grandchild) {
                    $promises[] = $this->detectLoop($parent, $grandchild);
                }
                return !empty($promises)
                    ? all($promises)->then(function() { return false; })
                    : false;
            }, function() {
                return false;
            });
    }