Documentation
¶
Overview ¶
Package tickgroup allows a collection of goroutines to call a subtask every set time interval.
Example ¶
This example uses the tickgroup package to create a simple 5 second timer.
ctx, cancel := context.WithCancel(context.Background())
// A tickgroup tg with a cancel context is initialized.
tg := New(ctx)
var i int
tg.Go(time.Second, func() error {
if i > 4 {
cancel()
return nil
}
// i is incremeneted every 1 second.
i++
fmt.Println(i)
return nil
})
// After 5 seconds the context is canceled and Wait() returns a nil value, which ceases the process.
if err := tg.Wait(); err != nil {
fmt.Println(err)
}
Output: 1 2 3 4 5
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
A Group is a collection of goroutines working on subtask that are spawned on a set interval per task.
func WithContext ¶
WithContext creates a child context from the given context, and uses that to control context cancelation.
Click to show internal directories.
Click to hide internal directories.