Closed channel vs nil channel

I work with Go channels and I was wondering what is the difference between closing a channel and setting it to zero?

Edit:

In this example , I would like to disable the sender and receiver, whether closing the channel or setting to zero. What is the best practice for this?

+4
source share
2 answers

Setting the channel variable to nil simply sets the variable to nil, leaving the channel that previously referred to the initialized one.

This is the same as setting any other variable to nil.

If there are other links to the channel, you can access it. If not, it will be garbage collection.

, nil - . , :

  • nil
+6

. , . nil . .

+2

Source: https://habr.com/ru/post/1675628/


All Articles