Fork me on GitHub
#core-async
<
2015-12-01
>
danielgrosse07:12:15

I need some help, with this problem: I have a map which has some channels in it. I want to fill them in one function, and read it in another function. How could I handle this?

(def container {:channel1 (chan)
:channel2 (chan)})

(defn func1 [container]
(go
(>! (:channel2 container) (<! (:channel1 container))
))

(defn func2 [container]
(go
(println (<! (:channel2 container)))

(>!! (:channel1 container) „Test")

danielgrosse07:12:37

Is this possible?

sander12:12:36

is there a way to get more detail for this error in cljs/node.js? https://gist.github.com/sander/7699c3912286f3c3fe53

sander12:12:56

i'm wondering which pipe call in my source code causes it, for example

sander12:12:06

think I found it, by checking all involved chans for actually being nil

erik_price12:12:25

danielgrosse: It’s hard to tell what you’re trying to do, but fwiw, you’re never calling func1 and func2 in that code snippet.

danielgrosse12:12:41

@erik_price: I’m just getting my head around async. And the documentation I found in the web, weren’t so much helpful. I just found a way, with put! and take! to achive it.

codemartin14:12:22

Is there some way to find out if you are inside a go block? Like (go (= true (am-i-in-a-go-block?)))?

codemartin14:12:37

(= false (am-i-in-a-go-block?))

swizzard14:12:57

@codemartin: why would the code need to know?

codemartin14:12:01

@swizzard: mostly for my repl - I keep doing (while true (...)) and then everything hangs, if I don't do it in a go-block.

swizzard14:12:49

so your non-terminating process doesn't terminate?

swizzard14:12:23

oh so you wanna be able to like short-circuit or whatever if you're in the main thread

swizzard14:12:29

so i don't know for sure, but i will go out on a limb and say that if there is a way to identify which thread some block of code is running in, it's likely to be some extremely ugly and unclojuric piece of interop magic dependent on obscure/intentionally obscured java internals

swizzard14:12:57

and your better bet would be to mock out your data/termination condition when playing around in the repl

codemartin14:12:41

@swizzard: maybe step one is to start using termination conditions at all! Another solution is not doing (while true), but

;;; pseudocode
(defn go-forever [& form] (go (while true form)))
instead

swizzard14:12:32

but all that go-forever is gonna do is return to the main thread

swizzard14:12:59

so unless you're e.g. tailing a log your form is writing to, you'll be in the dark

swizzard14:12:27

and i've personally lost too many hours to assumptions about program state to let someone else make the same mistakes simple_smile

codemartin14:12:54

Yeah it is only for side-effecty code (just like go).