This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-03
Channels
- # beginners (446)
- # boot (16)
- # cljs-dev (2)
- # cljsrn (30)
- # clojars (2)
- # clojure (143)
- # clojure-finland (1)
- # clojure-greece (1)
- # clojure-nl (1)
- # clojure-russia (2)
- # clojure-spec (20)
- # clojure-uk (7)
- # clojurescript (167)
- # code-reviews (1)
- # community-development (12)
- # core-async (27)
- # cursive (3)
- # data-science (9)
- # datascript (2)
- # emacs (1)
- # graphql (46)
- # immutant (5)
- # jobs (2)
- # leiningen (1)
- # luminus (1)
- # lumo (76)
- # off-topic (79)
- # perun (2)
- # protorepl (33)
- # re-frame (21)
- # reagent (62)
- # ring-swagger (1)
- # rum (18)
- # spacemacs (6)
- # specter (4)
- # test-check (4)
- # unrepl (9)
- # untangled (2)
- # vim (4)
- # yada (1)
actual thread, or go block?
@noisesmith core.async/thread
yeah, real thread cancellation in the jvm is tricky
future-cancel
might work if it's in the process of doing anything interruptable though
remember that thread doesn't return a handle to the thread, it returns a channel that receives the return value
the hard part would be even getting a handle on the thread you want to stop...
shutting threads down from the outside isn't really a plan that works out well on the jvm
you could use a future instead, but then you can't just park on the return value (though you could write a channel from the future etc.)
with a future, future-cancel works, as long as the future eventually calls some interruptable method (sleep, io)
that tends to be much more elegant, yes
if it's looping you could have it check a condition (eg. a channel or primise or delay)
@lxsameer this returns a channel you can read, and also a future that you can cancel
(defmacro cthread [& body] `(let [c# (>/chan) f# (future (>/put! c# (do ~@body)))] [c# f#]))
hmm with a reify a single object could be both...
@lxsameer so I figured hey, the thread created should be cancelled if possible if you close the chan https://clojurians.slack.com/archives/C053PTJE6/p1496527008640597
hmmm that's weird because i closed the channel , the I exit from the loop but the thread still running
wait, using the code I just shared?
the existing core.async/thread does not close the chan, but I made a new one I just linked to
that's what I mean
the one I linked to should be just like async/thread except cancelling the thread