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;
}
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<ModalSubmitInteraction<boolean> | null> {
return new Promise<ModalSubmitInteraction<boolean> | null>(res => {
this.run(interaction => {
res(interaction);
});
if (timeout && timeout > 0) {
setTimeout(() => {
res(null);
}, timeout);
}
});
}
/**