frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

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

https://www.inngest.com/blog/hanging-promises-for-control-flow
38•goodoldneon•2h ago

Comments

dimitropoulos•2h ago
> Libraries like Effect have increased the popularity of generators, but it's still an unusual syntax for the vast majority of JavaScript developers.

I'm getting so tired of hearing this. I loved the article and it's interesting stuff, but how many more decades until people accept generators as a primitive??

used to hear the same thing about trailing commas, destructuring, classes (instead of iife), and so many more. yet. generators still haven't crossed over the magic barrier for some reason.

yeittrue•1h ago
Generators peaked in redux- saga and thunk days before we had widespread support for async/await.

You're right, mostly pointless syntax (along with Promise) now that we can await an async function anyway, especially now with for .. of to work with Array methods like .map

But there are still some use cases for it, like with Promise. Like for example, making custom iterators/procedures or a custom delay function (sync) where you want to block execution.

horsawlarway•1h ago
There just aren't that many spots where the average js dev actually needs to touch a generator.

I don't really see generators ever crossing into mainstream usage in the same way as the other features you've compared them to. Most times... you just don't need them. The other language tools solve the problem in a more widely accessible manner.

In the (very limited & niche) subset of spots you do actually need a generator, they're nice to have, but it's mostly a "library author" tool, and even in that scope it's usage just isn't warranted all that often.

gbuk2013•29m ago
It is a specialised instrument but a useful one: batch processing and query pagination are first class use cases for generators that can really simplify business logic code. Stream processing is another and in fact Node.js streams have had a generator API for several releases now.
game_the0ry•1h ago
Off topic, but that site has really nice design
williamdclt•1h ago
Mh, I couldn't read due to the huge contrast and had to switch to reader mode, so...
jazzypants•1h ago
I personally find it to be perfectly readable. I've heard of people with issues with white text on a black background, but I don't fully understand it. Do you have astigmatism?
game_the0ry•1h ago
I mean, I'm not a designer but it was interesting enough to call out.
pjc50•1h ago
I like how C# handles this. You're not forced to support cancellation, but it's strongly encouraged. The APIs all take a CancellationToken, which is driven by a CancellationTokenSource from the ultimate caller. This can then either be manually checked, or when you call a library API it will notice and throw an OperationCancelledException.

Edit: note that there is a "wrong" way to do this as well. The Java thread library provides a stop() function. But since that's exogenous, it doesn't necessarily get cleaned up properly. We had to have an effort to purge it from our codebase after discovering that stopping a thread while GRPC was in progress broke all future GRPC calls from all threads, presumably due to some shared data structure being left inconsistent. "Cooperative" (as opposed to preemptive) cancel is much cleaner.

CharlieDigital•1h ago
C# has very good support for this.

You can even link cancellation tokens together and have different cancellation "roots".

esprehn•1h ago
AbortSignal is same thing on the Web. It's unfortunate TC39 failed to ever bring a CancelToken to the language to standardize the pattern outside browsers.
runarberg•1h ago
TC39 seems to be failing at many things for the past 10 years.
teraflop•1h ago
I am surprised that you had to go out of your way to remove Thread.stop from existing Java code. It's been deprecated since 1998, and the javadoc page explains pretty clearly why it's inherently unsafe.

It's hard to miss all the warnings unless you're literally just looking at the method name and nothing else.

pjc50•58m ago
I was certainly surprised to see it when I found it.
cush•1h ago
GC can be very slow. Relying on it for control flow is a bold move
BlueGreenMagick•28m ago
I don't think the control flow relies on GC.

The control flow stops because statements after `await new Promise(() => {});` will never run.

GC is only relied upon to not create a memory leak, but you could argue it's the same for all other objects.

augusto-moura•15m ago
Not that very slow for web applications. Maybe for real time or time-sensitive applications. For most day to day web apps GC pauses are mostly unnoticeable, unless you are doing something very wrong
eithed•1h ago
> Promise itself has no first-class protocol for cancellation, but you may be able to directly cancel the underlying asynchronous operation, typically using AbortController.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

mohsen1•1h ago
Back in 2012 I was working on a Windows 8 app. Promises were really only useful on the Windows ecosystem since browser support was close to non existent. I googled "how to cancel a promise" and the first results were Christian blogs about how you can't cancel a promise to god etc. Things haven't changes so much since, still impossible to cancel a promise (I know AbortSignal exists!)
abraxas•53m ago
and so the thirty year old hackathon continues...
afarah1•50m ago
You can also race it with another promise, which e.g. resolves on timeout.
TZubiri•47m ago
If I know the javascript ecosystem, and I think I do, this is an opportunity for some undergrad from Kazakhstan to create a library called 'Pinky' that offers unbreakable promises, which will have 1M downloads on npm and 10K stars on github, and will allow the dev to get a US Visa and employment.

The library will get additional maintainers until it balloons into 100Kloc with features like reading config files, which would need to eventually get split into a transitive dependency called configy, until one day a maintainer clicks on an enlarge penis link or gets phished by a fake AI girlfriend that was actually a russian dude, and it hits half of the javascript ecosystem because it had become a transitive dependency for every single package, and then everyone switches to a new package manager that somehow survived this due to a security feature, (but it was actually because no one uses that package manager and so the attacker didn't target it) also it's faster and used by the top startups of YC so it's very sexy and it can now be your girlfriend so you don't need a fake AI girlfriend and devs don't get supply chained anymore.

seattle_spring•17m ago
> If I know the javascript ecosystem, and I think I do

You think you do, but...

Show HN: Brutalist Concrete Laptop Stand (2024)

https://sam-burns.com/posts/concrete-laptop-stand/
393•sam-bee•5h ago•147 comments

Cloudflare targets 2029 for full post-quantum security

https://blog.cloudflare.com/post-quantum-roadmap/
58•ilreb•2h ago•22 comments

Moving fast in hardware: lessons from lab to $100M ARR

https://blog.zacka.io/p/simplify-then-add-lightness-bc4
25•rryan•1h ago•4 comments

We found an undocumented bug in the Apollo 11 guidance computer code

https://www.juxt.pro/blog/a-bug-on-the-dark-side-of-the-moon/
276•henrygarner•5h ago•143 comments

Good Taste the Only Real Moat Left

https://rajnandan.com/posts/taste-in-the-age-of-ai-and-llms/
24•speckx•24m ago•13 comments

Dropping Cloudflare for Bunny.net

https://jola.dev/posts/dropping-cloudflare
222•shintoist•2h ago•101 comments

Claude Code is locking people out for hours

https://github.com/anthropics/claude-code/issues/44257
144•sh1mmer•1h ago•146 comments

Show HN: A cartographer's attempt to realistically map Tolkien's world

https://www.intofarlands.com/atlasofarda
92•intofarlands•4h ago•16 comments

Every GPU That Mattered

https://sheets.works/data-viz/every-gpu
239•jonbaer•7h ago•129 comments

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

https://www.inngest.com/blog/hanging-promises-for-control-flow
38•goodoldneon•2h ago•26 comments

9 Mothers (YC P26) Is Hiring – Lead Robotics and More

https://jobs.ashbyhq.com/9-mothers?utm_source=x8pZ4B3P3Q
1•ukd1•2h ago

Identify a London Underground Line just by listening to it

https://tubesoundquiz.com/
132•nelson687•6h ago•41 comments

Global Physics Photowalk: 2025 winners revealed

https://www.quantamagazine.org/global-physics-photowalk-2025-winners-revealed-20260401/
11•ibobev•3d ago•1 comments

SQLite in Production: Lessons from Running a Store on a Single File

https://ultrathink.art/blog/sqlite-in-production-lessons
80•thunderbong•3d ago•57 comments

My Experience as a Rice Farmer

https://xd009642.github.io/2026/04/01/My-Experience-as-a-Rice-Farmer.html
288•surprisetalk•5d ago•137 comments

Wi-Fi That Can Withstand a Nuclear Reactor: This receiver chip can take it

https://spectrum.ieee.org/robotics-in-nuclear-industry
53•voxadam•4d ago•2 comments

Show HN: Stop paying for Dropbox/Google Drive, use your own S3 bucket instead

https://locker.dev
182•Zm44•5h ago•147 comments

DeiMOS – A Superoptimizer for the MOS 6502

https://aransentin.github.io/deimos/
51•Aransentin•5h ago•15 comments

Blackholing My Email

https://www.johnsto.co.uk/blog/blackholing-my-email/
122•semyonsh•7h ago•13 comments

Haunting Photos Show the Aftermath of the Kursk Submarine Disaster in 2000

https://rarehistoricalphotos.com/kursk-submarine-disaster-photos/
96•mooreds•5d ago•22 comments

Show HN: Pion/handoff – Move WebRTC out of browser and into Go

https://github.com/pion/handoff
63•Sean-Der•4h ago•11 comments

12k Tons of Dumped Orange Peel Grew into a Landscape Nobody Expected (2017)

https://www.sciencealert.com/how-12-000-tonnes-of-dumped-orange-peel-produced-something-nobody-im...
22•pulisse•31m ago•1 comments

AI may be making us think and write more alike

https://dornsife.usc.edu/news/stories/ai-may-be-making-us-think-and-write-more-alike/
171•giuliomagnifico•4h ago•164 comments

Breaking the console: a brief history of video game security

https://sergioprado.blog/breaking-the-console-a-brief-history-of-video-game-security/
64•sprado•6h ago•18 comments

Running Out of Disk Space in Production

https://alt-romes.github.io/posts/2026-04-01-running-out-of-disk-space-on-launch.html
110•romes•4d ago•51 comments

Sam Altman may control our future – can he be trusted?

https://www.newyorker.com/magazine/2026/04/13/sam-altman-may-control-our-future-can-he-be-trusted
1788•adrianhon•1d ago•730 comments

Show HN: Ghost Pepper – Local hold-to-talk speech-to-text for macOS

https://github.com/matthartman/ghost-pepper
432•MattHart88•20h ago•190 comments

Floating point from scratch: Hard Mode

https://essenceia.github.io/projects/floating_dragon/
73•random__duck•2d ago•16 comments

Record wind and solar saved UK from gas imports worth £1B in March 2026

https://www.carbonbrief.org/analysis-record-wind-and-solar-saved-uk-from-gas-imports-worth-1bn-in...
85•mindracer•4h ago•58 comments

Three hundred synths, 3 hardware projects, and one app

https://midi.guide/blog/three-hunded-synths-one-app/
103•ductionist•11h ago•13 comments