This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-26
Channels
- # aleph (9)
- # announcements (31)
- # babashka (23)
- # beginners (35)
- # biff (2)
- # calva (5)
- # cider (10)
- # clara (11)
- # clerk (114)
- # clj-kondo (18)
- # cljdoc (37)
- # clojars (7)
- # clojure (24)
- # clojure-austin (10)
- # clojure-europe (27)
- # clojure-nl (1)
- # clojure-norway (23)
- # clojure-uk (2)
- # clojurescript (18)
- # conjure (2)
- # core-async (6)
- # cursive (21)
- # datomic (3)
- # fulcro (15)
- # introduce-yourself (7)
- # lsp (32)
- # malli (57)
- # meander (5)
- # music (1)
- # nbb (2)
- # off-topic (17)
- # pathom (6)
- # rdf (4)
- # reagent (8)
- # releases (2)
- # shadow-cljs (4)
- # slack-help (23)
- # spacemacs (6)
- # tools-build (32)
Hello! If I read the docs correctly then there is no way to cancel the operation inside a/thread, eg after a timeout, correct? I'd need to impl myself inside it's body (eg checking a channel for being closed)...
I don't believe a non-cooperative method exists, either on the JVM or in javascript land. In other words, the code running in your thread must provide support for interruption.
However, if you're running in a thread on the jvm, you can also use .interrupt
(https://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html). Thread .interrupt
is supported by some of the java standard library. It can be tricky to get right, but sometimes, it's the right tool.
Right, thank you. But if I use a/thread then I only have a channel, not the thread. I guess inside its body at the very start I could use currentThread
and store it somewhere so that an external process can .interrupt it. Likely do it in try … finally and remove it from that place in the finally block so that it is not interrupted when it already is used for other purposes then the a/thread.
I guess trying to interrupt a thread created by a/thread
is a bad idea since threads come from a cached thread pool and the thread may have already moved onto another go block.
Depending on if you want to use .interrupt
, you could also use your own thread pool that helps support this use case.
Using an "interrupt channel" is also a good option in many cases.
Cancelling and interrupting code is always tricky. Maybe the jvm's loom project will help in the future.