mirror of
https://github.com/twentyhq/twenty.git
synced 2026-08-04 11:42:49 -04:00
26 lines
539 B
TypeScript
26 lines
539 B
TypeScript
type ExpectEventuallyOptions = {
|
|
timeoutMs?: number;
|
|
intervalMs?: number;
|
|
};
|
|
|
|
export const expectEventually = async (
|
|
assertion: () => Promise<void> | void,
|
|
{ timeoutMs = 10_000, intervalMs = 100 }: ExpectEventuallyOptions = {},
|
|
): Promise<void> => {
|
|
const startedAt = Date.now();
|
|
|
|
for (;;) {
|
|
try {
|
|
await assertion();
|
|
|
|
return;
|
|
} catch (error) {
|
|
if (Date.now() - startedAt > timeoutMs) {
|
|
throw error;
|
|
}
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
}
|
|
}
|
|
};
|