diff --git a/validate-tree/src/index.ts b/validate-tree/src/index.ts index 95af025..ea8e679 100644 --- a/validate-tree/src/index.ts +++ b/validate-tree/src/index.ts @@ -83,21 +83,24 @@ export function validateTree( * the name of a child instance, which should have a corresponding value which is this same kind of tree. * There is also a shorthand syntax available, where setting a key equal to a className is equivalent * to an object with `$className` defined. Hence `Things: "Folder"` is equivalent to `Things: { $className: "Folder" }` + * @param warnAfter How long to wait before warning about the tree not being found. + * If the value is 0 then no warning will be given. */ export function promiseTree( object: I, tree: T, + warnAfter: number = 5, ): Promise> { if (validateTree(object, tree)) { return Promise.resolve(object as I & EvaluateInstanceTree); } const connections = new Array() - const warner = Promise.delay(5) + const warner = Promise.delay(warnAfter) warner.then(() => { const violators = new Array() - if (!validateTree(object, tree, violators)) + if (warnAfter !== 0 && !validateTree(object, tree, violators)) warn(`[promiseTree] Infinite wait possible. Waiting for: ${violators.join(", ")}`) })