Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Not vice versa (the current design).

    select {
       case: <-chan1_whichIWantToCheckFirst
       default:
    }

    select {
       case: <-chan2_whichItreatTheSameAsChan3
       case: 0xFF ->chan3_whichItreatTheSameAsChan2
    }



Yes, as I have mentioned, there is performance loss, comparing to

    select {
       case: <-chan2_whichItreatTheSameAsChan3 // a higher priority
       case: 0xFF ->chan3_whichItreatTheSameAsChan2
    }


The real usecases where I need deterministic select, are so few that a small performance loss doesn't matter to me.


Sometimes, it is not related to performance loss, it is related to implementation cleanness and complexity.


A separate `select` with empty `default` is about as simple and clean as it gets. It is easy to read, easy to reason about, and, most importantly, conveys the intention of the code perfectly.


1) Is there really a performance loss compared to if select was deterministic?

2) What in the world do you need such code for?


1) surely.

2) just read:

     https://groups.google.com/g/golang-nuts/c/SXsgdpRK-mE/m/CT7UjJ3aBAAJ

     https://groups.google.com/g/golang-nuts/c/ZrVIhHCrR9o

     https://groups.google.com/g/golang-nuts/c/lEKehHH7kZY/m/SRmCtXDZAAAJ




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: