github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/protocol/timer.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package protocol
     4  
     5  // Timer is the interface that must implement by any timer.
     6  type Timer interface {
     7  	// if Init() called by nil for callback, client can use Signal() to block until timeout occur.
     8  	Init(callback func(arg any), arg any)
     9  
    10  	Start(d Duration)
    11  	Tick(first, interval Duration)
    12  	// if timer is a ticker, reset just change the interval not first tick duration.
    13  	Reset(d Duration) (alreadyActivated bool)
    14  
    15  	// Client must call Stop(), otherwise **"leaks"** occur
    16  	Stop() (alreadyStopped bool)
    17  
    18  	Signal() <-chan struct{}
    19  
    20  	Stringer
    21  }