4 ms·
I actually like the way it is (or can be) done in Haskell: since polling an “interrupted” status would be a side effect, instead they turn the problem on its he
by evincarofautumn 8y ago
I actually like the way it is (or can be) done in Haskell: since polling an “interrupted” status would be a side effect, instead they turn the problem on its head: you can throw an async exception to the task you want to interrupt, given its ID, and it behaves essentially as if the code it was just executing has thrown a synchronous exception.
Sounds spooky, and it does require writing code in an exception-safe way, but that’s generally easy: pure code is largely exception-safe by nature, and impure code can use “bracket” (“finally”, “mask”, “ResourceT”, &c.) to acquire & release resources—and should already be using these functions anyway to handle regular synchronous exceptions. Async exceptions are very useful for killing a task that’s using too much time/memory, or initiating a graceful shutdown.