github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/timeutil/timer.go (about)

     1  package timeutil
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // StopAndDrainTimer stops a timer and performs a non-blocking drain on its
     8  // channel. This allows a timer to be stopped and drained without any knowledge
     9  // of its current state.
    10  func StopAndDrainTimer(timer *time.Timer) {
    11  	timer.Stop()
    12  	select {
    13  	case <-timer.C:
    14  	default:
    15  	}
    16  }