title: How to stop AfterFunc before executing in Golang
body: <pre><code>var funcTimer *time.Timer
  
  func AddItem(){
  
     defer funcTimer.Stop()
  
     funcTimer = time.AfterFunc(1000*time.Millisecond, func() {
  
          fmt.Println("Executed")
  
     })
  
  }
  </code></pre>
  
  <p>My goal is trying to make this function as a debounce, in a way that if it is called rapidly without a time delay, the func call will not run.</p>
  
  <p>My problem here is <code>funcTimer.Stop()</code> does not seem to stop <code>time.AfterFunc</code> function</p>
  
  <p>In javascript, the equivalent of this is by using ClearTimeout and SetTimeout.</p>