Is there any equivalent in major popular languages like Python, Java, or JS of this?
Is there any equivalent in major popular languages like Python, Java, or JS of this?
Example:
maybeVal <— timeout 1000000 myFunction
Some people think that async exceptions are a pain because you nerd to be prepared that your code can be interrupted any time, but I think it's absolutely worth it because in all the other languages I encounter progress bars that keep running when I click the cancel button, or CLI programs that don't react to CTRL+C.In Haskell, cancellability is the default and carries no syntax overhead.
This is one of the reasons why I think Haskell is currently the best language for writing IO programs.
(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.)
Also, a sibling poster mentioned ZIO/Scala which does the Structured Concurrency thing out of the box.
https://github.com/ggoodman/context provides nice helpers that brings the DX a bit closer to Go.
There's a stop_token in some Microsoft C++ library but it's not nearly as convenient to interrupt a blocking operation with it.