title: Deadlock in channels communication between two packages - Golang
body: <p>Deadlock in channels communication between two packages - Golang.</p>
  <p>I have two packages that are communicated by two channels. One is main and the other has a function. When I run it, I obtain a deadlock.</p>
  <pre><code>package main
  
  import (
      functionspackage &quot;GoEjemplos/subFolder&quot;
      &quot;fmt&quot;
      &quot;sync&quot;
  )
  
  func main() {
      var wg sync.WaitGroup
  
      ChannelSendData := make(chan functionspackage.FunctionStruct, 1)
      defer close(ChannelSendData)
  
      data := functionspackage.FunctionStruct{
          FieldOne: 3.56,
          FieldTwo: 23,
      }
  
      ChannelSendData &lt;- data
  
      wg.Add(1)
      go functionspackage.FunctionExt(ChannelSendData, &amp;wg)
  
      recibe := &lt;-functionspackage.ChannelOutFunct
  
      fmt.Println(&quot;channelOut: &quot;, recibe)
  
      close(functionspackage.ChannelOutFunct)
  
      wg.Wait()
  }
  
  </code></pre>
  <p>The other package is</p>
  <pre><code>package functionspackage
  
  import &quot;sync&quot;
  
  type FunctionStruct struct {
      FieldOne float64
      FieldTwo int
  }
  
  var ChannelOutFunct chan float64
  
  func FunctionExt(RecibeChan chan FunctionStruct, wg *sync.WaitGroup) (ChannelOutFunct chan float64) {
  
      reciveData := &lt;-RecibeChan
  
      result := reciveData.FieldOne * float64(reciveData.FieldTwo)
  
      ChannelOutFunct &lt;- result
  
      wg.Done()
  
      return ChannelOutFunct
  }
  
  </code></pre>
  <p>This is the deadlock.</p>
  <pre><code>PS C:\Go-Project\src\GoEjemplos&gt; go run main.go
  fatal error: all goroutines are asleep - deadlock!
  
  goroutine 1 [chan receive (nil chan)]:
  main.main()
          C:/Go-Project/src/GoEjemplos/main.go:32 +0x13d
  
  goroutine 19 [chan send (nil chan)]:
  GoEjemplos/subFolder.FunctionExt(0xc0000d4000, 0xc0000a2070, 0xc0000c9f18)
          C:/Go-Project/src/GoEjemplos/subFolder/functionsPackage.go:19 +0x85
  created by main.main
          C:/Go-Project/src/GoEjemplos/main.go:30 +0x11a
  exit status 2
  PS C:\Go-Project\src\GoEjemplos&gt;
  </code></pre>
  <p>Could you explain it to me where is the problem?</p>
  <p>Thanks!</p>