DEV Community

Pavel Svitek
Pavel Svitek

Posted on

2

How to write a Backoff function in Typescript

Imagine you want to call your backend API (or other network operation) but it fails.

You would like to call it 2 or 3 times more with some delay. Much like how Gmail works when it tries to connect back after losing a connection.

The code below implements an async function that works just like that.

The code should be self-explainable, but feel free to ask in comments if anything is not clear.

The KUDOS for implementation of the original function backoffOrig() goes to Saša Savić
https://www.linkedin.com/feed/update/urn:li:activity:6655380458282594304

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay