zlacker

[parent] [thread] 1 comments
1. Valent+(OP)[view] [source] 2024-10-14 18:18:33

    (defn test-dbg7 [] ;; test buffers
        (record "test-dbg.svg"
                (let [c ^{:name "chan"} (async-dbg/chan 1)]
                  ^{:name "thread"}
                  (async-dbg/thread
                    (dotimes [n 3]
                      ^{:name "put it!"} (async-dbg/>!! c n))
                    ;; THE BUG IS HERE. FORGOT TO CLOSE GODAMNIT
                    #_(async-dbg/close! c))
                  (loop [x (async-dbg/<!! c)]
                    (when x
                      (println "-->" x)
                      (recur ^{:name "take it!"} (async-dbg/<!! c)))))))
The code above produces the following before hanging:

    --> 0
    --> 1
    --> 2
https://pasteboard.co/L4WjXavcFKaM.png

In this test case, everything sits nicely within the same let statement, but these puts and reads to the same channel could be in different source files, making the bug hard to track.

Once the bug is corrected the sequence diagram should look like this:

https://pasteboard.co/CCyGZKUUkVFL.png

replies(1): >>educti+h6
2. educti+h6[view] [source] 2024-10-14 18:59:12
>>Valent+(OP)
Ya I also needed some time to wrap my head around async programming but OP was talking about "use[ing] the wrong sigil at the wrong place" - that's not what your stumbling block is here, you forgot to close the channel and you have a loop statement that by design is going to read eternally from the channel so as long as the channel is open you're going to "hang". Doesn't have anything to do with mixing up "sigils", it's just that async programming has unique challenges.
[go to top]