Documentation
¶
Overview ¶
Package timerpool implements a global timer pool.
Example ¶
package main import ( "context" "fmt" "sync" "time" "github.com/env25/mpdlrc/internal/timerpool" ) func main() { var wg sync.WaitGroup ctx1 := context.TODO() wg.Add(2) timer1 := timerpool.Get(time.Second) go func() { defer wg.Done() select { case <-ctx1.Done(): timerpool.Put(timer1, false) return case <-timer1.C: timerpool.Put(timer1, true) } fmt.Println("1") }() ctx2, cancel2 := context.WithCancel(ctx1) timer2 := timerpool.Get(time.Second) go func() { defer wg.Done() select { case <-ctx2.Done(): timerpool.Put(timer2, false) return case <-timer2.C: timerpool.Put(timer2, true) } fmt.Println("2") }() cancel2() wg.Wait() }
Output: 1
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.