core-async

hifumi123 2024-01-24T02:04:54.440159Z

Is it an anti-pattern to implicitly return nil in a go block? If I understand core.async correctly, go blocks create channels that eventually put the return value of the form they wrap. I am also aware that many parts of core.async rely on an assumption that nil taken from channel implies channel is closed. Does this mean the following code is bad?

(go
  (try
    (do something that will not return nil)
    (catch Exception e
      (log something with e))))

2024-01-24T02:48:19.407329Z

You cannot actually put a nil value on a channel, so that does not result in a nil value on a channel

2024-01-24T02:48:48.743239Z

What happens in that case is the channel returned is just closed without a value being written to it

2024-01-24T02:49:30.577649Z

Whether that is a problem or not depends on what you are doing with the channel

hifumi123 2024-01-24T03:01:32.531059Z

in my case im simply taking a value from the channel, and I do not expect the channel to remain open after I take any value out of it

2024-01-24T03:04:26.357239Z

Take on an empty closed channel returns nil

cjohansen 2024-01-24T06:03:50.977599Z

This is fine, assuming you don't want to have information about why it failed.