How do you limit a request's time and cancel it?
Answer out loud or in your head first, then compare.
Answer
I decide how long I can wait for one attempt and for the whole task. In code I pass a cancellation signal, e.g. an AbortSignal, to the function that handles the network. When finished, I clean up timers and event listeners.
Promise.race with a timer alone can make me stop waiting, but it won't stop the other operation's work. That's an important difference. What's more, a dropped connection doesn't prove the remote server did nothing. If I sent a write, I need a way to check its result or protection against doing it twice. For a read, it's usually easier to retry safely than for creating a payment.
Why it matters: Prevents unbounded waiting and uncontrolled repetition of actions.
Possible follow-ups: What about a timeout when the write may already have been committed?
How did it go? Be honest — “Not yet” puts the question on your review list.
Start with
- B-P01 · What is Node.js, and how is it different from JavaScript in the browser? — JavaScript, TypeScript and Node.js
- B-P04 · What is a Promise? — JavaScript, TypeScript and Node.js
- B-P10 · What does TypeScript give you, and what doesn't it? — JavaScript, TypeScript and Node.js
Further reading
- Claude Platform: Tool use overview(opens in a new tab)Docs; accessed 22.10.2026. Client and server tools, the call, and a result matched by call ID.