refactor: update waitFor method to improve promise handling and timeout logic

This commit is contained in:
MARCROCK22 2025-06-19 11:24:54 -04:00
parent 35f1904920
commit cccf1ea2c4

View File

@ -90,20 +90,17 @@ export class Modal<T extends ModalBuilderComponents = TextInput> {
return this; return this;
} }
waitFor(func: ModalSubmitCallback, timeout: number): this { waitFor(timeout?: number): Promise<ModalSubmitInteraction<boolean> | null> {
this.run( return new Promise<ModalSubmitInteraction<boolean> | null>(res => {
interaction => this.run(interaction => {
new Promise(resolve => { res(interaction);
const timer = setTimeout(() => { });
resolve(null); if (timeout && timeout > 0) {
}, timeout); setTimeout(() => {
func(interaction).then((data: ModalSubmitInteraction) => { res(null);
clearTimeout(timer); }, timeout);
resolve(data); }
}); });
}),
);
return this;
} }
/** /**