chan chan question

73 views
Skip to first unread message

joe mcguckin

unread,
Jun 22, 2020, 3:51:18 PM6/22/20
to golang-nuts
I've been playing with this example code on the playground: https://play.golang.org/p/4l57Hqw9CLJ

In func  'goroutine':

       select {
        case errChan := <-requestChan:

How does this work? Does a channel send its name? Is 'errChan' some sort of special symbol?

Thomas Bushnell, BSG

unread,
Jun 22, 2020, 3:54:44 PM6/22/20
to joe mcguckin, golang-nuts
You can send any object you like across a channel of the appropriate type. It sends the actual object (in this case, the channel) just as for an integer, it sends the value, or for a map, the whole map.

errChan in the snippet you quote is an ordinary variable, and this is its declaration (like any := case).

The type of requestChan is "<-chan chan error", so the thing you read off it is "chan error", which means the type of errChan is a "chan error". (If you read from errChan, you get an "error".)

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/47d6fc3a-3f94-4661-b111-7c8fecb791d8o%40googlegroups.com.

joe mcguckin

unread,
Jun 22, 2020, 9:58:44 PM6/22/20
to golang-nuts
Thanks!


Reply all
Reply to author
Forward
0 new messages