Context cancellation (and it's propagation) is one of the best features in Go.<p>Is there any equivalent in major popular languages like Python, Java, or JS of this?
ZIO in Scala tracks this sort of thing except you don't have to remember to pass around or select on the ctx (it's just part of the fibre/"goroutine"); if it's cancelled, the fibre and its children just stops the next time it yields (so e.g. if it "selects" on anything or does any kind of IO).
Python async tasks can be cancelled. But, I don't think you can attach must context to the cancel (I think you can pass a text message), so it would seem the argument of what go suffered from would apply.<p>(I also think there's some wonkiness with and barriers to understanding Python's implementation that I don't think plagues Go to quite the same extent.)
All mainstream languages have it in one or more forms (either direct task I/O cancellation, or cancellation tokens or I/O polling that can include synthetic events) since otherwise several I/O patterns are impossible
C# has CancellationToken, but it’s just for canceling operations, not a general purpose context.
in JS, signals and AbortController can replicate some of the functionality but it's far less ergonomic than Go.<p><a href="https://github.com/ggoodman/context" rel="nofollow">https://github.com/ggoodman/context</a> provides nice helpers that brings the DX a bit closer to Go.
one of the reasons why i love writing control planes in Go.
Kotlin Coroutine's structured concurrency. Cancelling a parent automatically cancels child jobs, unless explicitly handled not to.
<a href="https://kotlinlang.org/docs/coroutines-basics.html" rel="nofollow">https://kotlinlang.org/docs/coroutines-basics.html</a>
Java's Virtual Threads (JVM 21) + the Structured Concurrency primitives (not sure exactly what's available in Java 21+) do this natively.<p>Also, a sibling poster mentioned ZIO/Scala which does the Structured Concurrency thing out of the box.
Not really, since they don't have `select`<p>There's a stop_token in some Microsoft C++ library but it's not nearly as convenient to interrupt a blocking operation with it.