49 / 81 · Module 14 — External Automated Testing of Mule Integrations · filtered: interview← prev⊞ allnext →
14.23Polling helper
Conceptually:
async function waitForAccount(
customerId: string,
timeoutMs = 30000
) {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
const account =
await findAccount(customerId);
if (account) return account;
await new Promise(r => setTimeout(r, 1000));
}
throw new Error(
`Account ${customerId} did not appear`
);
}
Then:
const account =
await waitForAccount(customer.customerId);