core-async

shaunlebron 2025-07-03T16:32:00.622619Z

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)))))

2025-07-03T17:30:42.605649Z

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

2025-07-03T21:28:09.648069Z

A global stop for repl development could make sense. I've definitely gotten some threads stuck at the repl before with core.async.

2025-07-03T21:28:52.257829Z

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.