This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-21
Channels
- # aws (3)
- # beginners (98)
- # boot (18)
- # cider (6)
- # cljsrn (8)
- # clojure (56)
- # clojure-dev (11)
- # clojure-spec (3)
- # clojure-turkiye (1)
- # clojurescript (34)
- # core-async (42)
- # cursive (8)
- # datascript (79)
- # defnpodcast (2)
- # dirac (13)
- # emacs (14)
- # jobs-discuss (3)
- # onyx (27)
- # overtone (1)
- # pedestal (1)
- # protorepl (1)
- # re-frame (40)
- # reagent (5)
- # unrepl (29)
- # vim (3)
hi all, im not sure if this is a core.async issue or a clojurescript/nodejs issue, but I am struggling to figure out the best way to shut down an app that has at least one (timeout) pending
in a nutshell, I have an (alt!) that waits on two channels: one of which is a core.async/timeout
but I find that my program hangs at shutdown until the timeout eventually fires...which is the common scenario because the timeout just an exceptional condition
so, i am wondering if there are some best practices here, or other advice...for instance, canceling the timeout, telling core.async to shutdown, a way to wait on a channel with a timeout, etc
the way to wait on a channel with a timeout is to use alt! or alts!
if your channel has a value before the timeout does, that's the value you will get
my (alt!) works as expected, but then my program cannot exit until the timer also fires
oh, add a third channel - called a poison-pill
close that channel when you want to exit
but never write to it
a closed channel returns nil immediately, so if it is one of your alts it will fire
hmm, the problem is not with the (alt!) firing...the logic is part of a command line app....so start -> (alt!) -> exit
what is it waiting for then?
in clojure I would say you need to run (shutdown-agents) but I don't think that applies in node
if the app is waiting on a timeout that you are not reading, that sounds like a bug to me
but, what if you call close! on the timeout channel?
using close! on a timeout works in my repl - let me double check in a node repl
it "feels" like node is still seeing something with active callbacks in the event loop, or whatever (not a node-internals expert)
I can probably write this a half dozen other ways, its just seemed like (alt!)+(timeout) was the idiomatic way to do it
just curious, where did you see the comment not to call close! on a timeout?
but if you want your whole app to exit, that caveat doesn't apply
too bad that it does that though