oops, forgot to close the done channel! ... the worker should do that: 
https://go.dev/play/p/kPAchZK0kKj

On Tuesday, September 2, 2025 at 7:35:55 PM UTC+1 Jason E. Aten 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.
>
> 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.
>
> 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
>

-- 
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/2035404b-25c6-4304-a307-9173363e480dn%40googlegroups.com.

Reply via email to