Search code examples
gochannelgoroutine

Cannot use type chan []string) as type []chan string?


package main

import "fmt"

func x(foo []string, cz chan string) {
    for i := range foo {
        cz <- foo[i]
    }
}

func y(foo []string, cz chan string) {
    for i := range foo {
        cz <- foo[i]
    }
}

type cz struct {
    cSlice []chan string
}

func main() {

    var quality []string = make([]string, 2)
    quality[0] = "hello"
    quality[1] = "world"
    //name := []string{"mother", "earth"}

    var channel cz

    for i := range channel.cSlice {
        go x(quality, channel.cSlice[i])
        go y(quality, channel.cSlice[i])
        x, y := <-channel.cSlice[i], <-channel.cSlice[i]
        fmt.Println(x, y)
    }
}

Nothing gets received now hmm...

Update ^

... need more text.

... and then a little more. Ok how much more?

I really can't believe this. fdsaf asf asfasdfdasfadfd


Solution

  • cannot use channel.cSlice (type chan []string) as type []chan string in argument to x
    cannot use channel.cSlice (type chan []string) as type []chan string in argument to y
    

    Read the error messages.

    type chan []string

    type []chan string

    They are different.

    Playground: https://play.golang.org/p/CKhj8DUGTle