Skip to content

Commit

Permalink
Refactor mailcatcher util
Browse files Browse the repository at this point in the history
  • Loading branch information
alejsdev committed Jul 29, 2024
1 parent 24368de commit 2e2c9dd
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions frontend/tests/utils/mailcatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,17 @@ export function findLastEmail({
),
)

const findEmailPromise = new Promise<Email>(async (resolve, reject) => {
try {
while (true) {
const emailData = await findEmail({ request, filter })
const checkEmails = async () => {
while (true) {
const emailData = await findEmail({ request, filter })

if (emailData) {
resolve(emailData)
return
}

await new Promise((resolve) => setTimeout(resolve, 100))
if (emailData) {
return emailData
}
} catch (e) {
reject(e)
// Wait for 100ms before checking again
await new Promise((resolve) => setTimeout(resolve, 100))
}
})
}

return Promise.race([timeoutPromise, findEmailPromise])
return Promise.race([timeoutPromise, checkEmails()])
}

0 comments on commit 2e2c9dd

Please sign in to comment.