From 431ad8b6cd8f0ff08a10e1b7bafdae7dd248f267 Mon Sep 17 00:00:00 2001 From: Emre Aksoy <33837953+emre1791@users.noreply.github.com> Date: Sun, 28 Jan 2024 04:29:55 +0300 Subject: [PATCH] Refactor promiseTree add an argument to disable warning text --- validate-tree/src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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(", ")}`) })