Menu

Post image 1
Post image 2
1 / 2
0

Owned Async Work In TypeScript. Promise.race Does Not Cancel Your Work

DEV Community·AdmilsonCossa·25 days ago
#M0wrO83U
Reading 0:00
15s threshold

Why Promise.race, Promise.all, and async helpers need an ownership model for cancellation, cleanup, and production agent work. Three providers. One winner. Three invoices. const winner = await Promise . race ([ fetch ( OPENAI , { body }), fetch ( ANTHROPIC , { body }), fetch ( GEMINI , { body }), ]); Enter fullscreen mode Exit fullscreen mode It is easy to assume a race cancels the losers. Native Promise.race resolves on the first settlement and leaves every other promise running unless the caller wires cancellation into each branch. TCP completes. Tokens bill. .then callbacks fire. Cleanup remains a manual convention. Promise.any and Promise.all have the same ownership gap. Native promises model values, not ownership. There is no ownership parent, no built-in cancellation path, and no scope cleanup contract. There is still work running after the value settles.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More