DEV Community

Why setTimeout is Lying to Your Retry Logic (opens in new tab)

Discussed on DEV

You've written retry logic. It probably looks something like this: async function withRetry(fn, retries = 3) { for (let i = 0; i setTimeout(r, 200 * (i + 1))); } } } You test it locally. You simulate a slow dependency like this: const fakeDB = async () => { await new Promise(r => setTimeout(r, 200)); // simulate DB return { id: 1, name: 'test' }; }; Your retry logic works. Tests...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help