Menu

1 / 2

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

DEV Community·AdmilsonCossa·6 months ago
#M0wrO83U
#ai#javascript#typescript#race#promise
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.…

Continue reading — create a free account

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