title: Go lang multiplexing all goroutines are asleep - deadlock
body: <p>I wants to create a fan-in function using multiple go routines returning channel here is my code.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "math/rand"
      "sync"
      "time"
  )
  
  var wg, wg2 sync.WaitGroup
  
  func main() {
      final := talk(boring("Joe"), boring("Ann"))
      for i := 0; i &lt; 10; i++ {
          fmt.Println(&lt;-final)
      }
      fmt.Println("You are both boring I'm leaving")
  }
  
  func talk(input1, input2 &lt;-chan string) &lt;-chan string {
      out := make(chan string)
      go func() {
          wg.Add(1)
          for {
              out &lt;- &lt;-input1
          }
      }()
      go func() {
          wg.Add(1)
          for {
              out &lt;- &lt;-input2
          }
      }()
      wg.Done()
      close(out)
      return out
  }
  
  func boring(msg string) &lt;-chan string {
      c := make(chan string)
      for i := 0; i &lt; 5; i++ {
          c &lt;- fmt.Sprintf("%s%d\n", msg, i)
          time.Sleep(time.Duration(rand.Intn(1e3)) * time.Millisecond)
      }
      return c
  }
  </code></pre>
  
  <p>But I got an error after running above code</p>
  
  <blockquote>
    <p>all goroutines are asleep - deadlock</p>
  </blockquote>
  
  <p>I have tried to close channels but still it is giving me the error. I have tried to assign boring returned channels to Joe and Ann and then pass those channels to talk function for multiplexing still no success. I am new to go learning channels not clear on this concept. </p>