Documentation
¶
Overview ¶
Example (StartTimer) ¶
package main import ( "fmt" "github.com/go-gevent/gevent/internal/timingwheel" "time" ) func main() { tw := timingwheel.NewTimingWheel(time.Millisecond, 20) tw.Start() defer tw.Stop() exitC := make(chan time.Time, 1) tw.AfterFunc(time.Second, func() { fmt.Println("The timer fires") exitC <- time.Now() }) <-exitC }
Output: The timer fires
Example (StopTimer) ¶
package main import ( "fmt" "github.com/go-gevent/gevent/internal/timingwheel" "time" ) func main() { tw := timingwheel.NewTimingWheel(time.Millisecond, 20) tw.Start() defer tw.Stop() t := tw.AfterFunc(time.Second, func() { fmt.Println("The timer fires") }) <-time.After(900 * time.Millisecond) // Stop the timer before it fires t.Stop() }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TimingWheel ¶
type TimingWheel struct {
// contains filtered or unexported fields
}
TimingWheel is an implementation of Hierarchical Timing Wheels.
func NewTimingWheel ¶
func NewTimingWheel(tick time.Duration, wheelSize int64) *TimingWheel
NewTimingWheel creates an instance of TimingWheel with the given tick and wheelSize.
func (*TimingWheel) AfterFunc ¶
func (tw *TimingWheel) AfterFunc(d time.Duration, f func()) *Timer
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
func (*TimingWheel) Stop ¶
func (tw *TimingWheel) Stop()
Stop stops the current timing wheel.
If there is any timer's task being running in its own goroutine, Stop does not wait for the task to complete before returning. If the caller needs to know whether the task is completed, it must coordinate with the task explicitly.
Click to show internal directories.
Click to hide internal directories.