On Tue, Sep 2, 2025 at 2:36 PM Jason E. Aten <j.e.a...@gmail.com> wrote:

> On Tuesday, September 2, 2025 at 7:09:02 PM UTC+1 David Finkel wrote:
>
> I don't think channel receive order is random when the senders are blocked.
> Sending goroutines are queued in a linked list in FIFO order within the
> runtime's channel struct (hchan)
> <https://cs.opensource.google/go/go/+/master:src/runtime/chan.go;l=45;drc=a8564bd412d4495a6048f981d30d4d7abb1e45a7>
>
>
> Interesting--thanks for pointing this out, David.
>
> I think this is an implementation detail rather than a promise made by the
> language spec, no?
> i.e. something that is subject to change since the specification does not
> guarantee it.
>
Good point.
I just rechecked the language spec to be sure, and yeah, that's not
guaranteed.

>
> In other words: beginners, you should not depend on it. Arguably since its
> not in the spec, it
> ought to be randomized to prevent assuming it will always hold... since it
> could change in the future.
>
Good advice.

>
> For replies I use the ticket + close-a-done-channel pattern, rather than
> single reply channel. Thus the
> worker never has to block itself once it is done with the work, and
> multiple parties can
> observe that the job has finished if they have a pointer to it. See for
> example https://go.dev/play/p/ggviji5FfYz
>
That's definitely a useful strategy in cases where you might have multiple
observers.

> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/52d5a833-3b7e-47a2-a95a-5c2d6da63cacn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/52d5a833-3b7e-47a2-a95a-5c2d6da63cacn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CANrC0BiKc%3DAfG13-%3D3mLv3XYxAT9mrRWDTovNcAoY8k_YNjo-A%40mail.gmail.com.

Reply via email to