title: Interrupting an infinite loop in Golang with signals
body: <p>I'm trying to make a program that uses signals to interrupt an infinite counter loop. I've managed to interrupt the program with SIGINT (ctrl + C), but I'm unable to interrupt it otherwise. I'm wondering if I can make other ways of interrupting the loop, for example by pressing the Q key while it is running in the terminal.</p>
  
  <p>I've made two Go-files, the first one containing the actual infinite loop:</p>
  
  <pre><code>package infinite
  
  import "fmt"
  import "time"
  
  func Infinite01 (msg string) {
  for i := 0; ; i++ {
      fmt.Println(msg, i)
      time.Sleep(time.Second)
      }
  }
  </code></pre>
  
  <p>And then the file to catch the SIGINT signal and interrupt the loop:</p>
  
  <pre><code>package main
  
  import (
  "./infinite"
  "os/signal"
  "os"
  "fmt"
  )
  
  func main() {
  sigs := make(chan os.Signal, 1)
  signal.Notify(sigs, os.Interrupt)
  go func() {
      &lt;-sigs
      fmt.Printf("You pressed ctrl + C. User interrupted infinite loop.")
      os.Exit(0)
  }()
  Loop()
  }
  
  func Loop() {
  infinite.Infinite01("Look, I can count forever:")
  }
  </code></pre>