title: How do I stop gocron jobs efficiently?
body: <p>I am doing something like this:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "time"
  
      "github.com/jasonlvhit/gocron"
  )
  
  func jobs(quit &lt;-chan bool) {
      for {
          select {
          case &lt;-quit:
              return
          default:
              //cron jobs
              g := gocron.NewScheduler()
              g.Every(1).Second().Do(stuff)
              &lt;-g.Start()
          }
      }
  }
  
  func stuff() {
      fmt.Println("doing job")
  }
  
  func main() {
      q := make(chan bool)
      go jobs(q)
      time.Sleep(3 * time.Second)
  
   //to quit the goroutine
      q &lt;- true    
      close(q)
      fmt.Println("main")
  }
  </code></pre>
  
  <p>I'm trying to stop the gocrons by killing the goroutine by closing the channel but I'm not able to stop gocron jobs. I am getting output </p>
  
  <pre><code>            doing job
              doing job
              doing job
              doing job
              doing job
              doing job
              doing job
              .
              .
  </code></pre>
  
  <p>Instead of </p>
  
  <pre><code>            doing job
              doing job
              doing job
              main
  </code></pre>
  
  <p>What am I doing wrong? Is there any better solution to stop gocron jobs?</p>