How does make(chan bool) behave differently from make(chan bool, 1)?

后端 未结 3 1655
南方客
南方客 2020-12-31 08:52

My question arises from trying to read a channel, if I can, or write it, if I can, using a select statement.

I know that channels specified like m

3条回答
  •  半阙折子戏
    2020-12-31 09:45

    An unbuffered channel means that read and writes from and to the channel are blocking.

    In a select statement:

    • the read would work if some other goroutine was currently blocked in writing to the channel
    • the write would work if some other goroutine was currently blocked in reading to the channel
    • otherwise the default case is executed, which happens in your case A.

提交回复
热议问题