Has anyone written a macro for making all inner forms interruptible? I’m imagining a global channel that can be closed:
(go
(allowing-interrupt my-global-close-ch
(loop []
...
(
(go
(try
(loop []
...
(alt! my-global-close-ch (throw (ex-info "interrupted" {:type :my-interrupt}))
(timeout 1000) ([v] v)
:priority true)
(let [m (alt! my-global-close-ch (throw (ex-info "interrupt" {:type :my-interrupt}))
in-ch ([v] v)
:priority true)]
...))
(catch Exception ex
(if (= :my-interrupt (:type (ex-data ex)))
(log/info "exiting on interrupt")
(throw ex)))))
I like the pattern of passing in a stop channel better than some magic global. And there is a good chance you should be waiting on a timeout somewhere too
A global stop for repl development could make sense. I've definitely gotten some threads stuck at the repl before with core.async.
But for actual logic, I think I'd agree with hiredman, either you'd want to go with a bigger structured concurrency DSL, or be more explicit.