what is wrong with my async code
(let [ch (async/chan)
result (do
(println "inside do")
(async/timeout 50)
(async/>!! ch "bar")
ch)]
(println (async/it only prints "inside do" but not bar
If I increase the channel size to 2 then it prints "bar"
Writing to ch will block until someone reads from the channel since it's unbuffered. Adding a buffer of 2 means that it can hold two values before blocking.
also calling (async/timeout 50) won't do anything. You probably meant (async/<!! (async/timeout 50)).
async/timeout returns a channel.
(async/chan) returns an unbuffered channel. Try (async/chan 1) to see the difference.
Thanks @smith.adriane
Your code doesn't start any new threads, so you have a thread attempting to write to a channel with no one waiting to read from the channel, so your thread just blocks
You should think of this like a tag team wrestling match. When you read/write to a channel, you're tagging out and tagging in another process.