Which of the following code snippets contains an error or potential issue related to channel operations? Option 1 package main func main() { ch := make(chan int) ch <- 1 } Option 2 package main func main() { ch := make(chan int, 1) ch <- 1 } Option 3 package main func main() { ch := make(chan int, 1) ch <- 1 <-ch } Option 4 package main func main() { ch := make(chan int) close(ch) <-ch } Option 5 package main func main() { ch := make(chan int, 3) ch <- 4 }
Golang
Could you tell about your experience with open source projects and give examples of your contributions?
Is it possible to pass an arbitrary number of arguments to a function?
How do you deploy? What are the steps in the pipeline?
Does Go have dynamic typing?
How does Go ensure thread safety?
What are the ways to declare a WaitGroup? How to write a value into a channel?
What does the range of channels return? Is the record 'for _, c := range chs' valid?
How were the tests conducted in the CI/CD pipeline? What was monitored?
func fanin[T any](chs ...<-chan T) chan T { out := make(chan T) wg := sync.WaitGroup{} for _, ch := range chs { wg.Add(1) go func(c <-chan T) { defer wg.Done() for v := range c { out <- v } }(ch) } go func() { wg.Wait() close(out) }() return out } func main() { ch1 := make(chan int, 5) ch2 := make(chan int, 5) for i := 1; i <= 5; i++ { ch1 <- i ch2 <- i * 2 } close(ch1) close(ch2) fmt.Println(fanin(ch1, ch2)) }