From cccf1ea2c407b6a754a1a20b2532741f5cdd0c97 Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Thu, 19 Jun 2025 11:24:54 -0400 Subject: [PATCH] refactor: update waitFor method to improve promise handling and timeout logic --- src/builders/Modal.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/builders/Modal.ts b/src/builders/Modal.ts index 150e037..4618014 100644 --- a/src/builders/Modal.ts +++ b/src/builders/Modal.ts @@ -90,20 +90,17 @@ export class Modal { return this; } - waitFor(func: ModalSubmitCallback, timeout: number): this { - this.run( - interaction => - new Promise(resolve => { - const timer = setTimeout(() => { - resolve(null); - }, timeout); - func(interaction).then((data: ModalSubmitInteraction) => { - clearTimeout(timer); - resolve(data); - }); - }), - ); - return this; + waitFor(timeout?: number): Promise | null> { + return new Promise | null>(res => { + this.run(interaction => { + res(interaction); + }); + if (timeout && timeout > 0) { + setTimeout(() => { + res(null); + }, timeout); + } + }); } /**