Sobes.tech
Junior — Senior

Optimization and refactoring of Go code with channels

livecode

Task condition

It is necessary to improve the program structure by removing potential locking issues and making it more readable.

func main() {
    dataCh := make(chan int)

    for val := range dataCh {
        fmt.Println(val)
    }

    go func() {
        dataCh <- 1
        dataCh <- 2
        dataCh <- 3
    }()
}