mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
refactor: update waitFor method to improve promise handling and timeout logic
This commit is contained in:
parent
35f1904920
commit
cccf1ea2c4
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user