Home / Companies / Inngest / Blog / Post Details
Content Deep Dive

You can't cancel a JavaScript promise (except sometimes you can)

Blog post from Inngest

Post Details
Company
Date Published
Author
Aaron Harper
Word Count
2,894
Company Posts That Month
9
Language
-
Hacker News Points
-
Post removed?
No
Summary

JavaScript lacks a built-in method for canceling promises, presenting challenges in interrupting async functions smoothly without leaving resources in a compromised state. While the TC39 committee considered adding cancellation in 2016, the proposal was abandoned due to concerns about the complexity it would introduce. An alternative method involves using a promise that never resolves, which effectively stops a function without throwing exceptions or requiring special handling in the code, as demonstrated by the Inngest TypeScript SDK for interrupting async workflows in serverless environments. This method allows for memoization of steps and continuation across multiple invocations, while relying on JavaScript's garbage collector to handle suspended functions without memory leaks, provided that no references to these promises remain. Although generators offer a clean interruption mechanism, they impose a different syntax, whereas the unresolved promise approach maintains the familiar async/await syntax without the pitfalls of try/catch swallowing interruptions, thus enabling a seamless control flow in JavaScript applications.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
Serverless 2 678 211 91 -7%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.