Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain <-(chan string)(nil)

Tags:

go

I found this <-(chan string)(nil) strange construct in the Gobetween sources.

  • Is it just a fancy way to block forever or it has some kind of advantage over select{}?
  • How to parse this statement?
like image 842
JAre Avatar asked Jul 21 '26 02:07

JAre


1 Answers

The statement casts nil as type chan string, then reads from it.

According to Dave Cheney's Channel Axioms:

A receive from a nil channel blocks forever

like image 197
MahlerFive Avatar answered Jul 23 '26 20:07

MahlerFive



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!