Documentation ¶
Overview ¶
Package routine is defined a routine group to manage many routines
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group interface { // Add is append routine func to group Add(fn func()) // Run is run group and wait all finish Run() }
Group is manage some routine in a group
func NewGroup ¶
func NewGroup() Group
NewGroup create routine group
Example ¶
rgp := NewGroup() var b bool var c []int var sum int32 // add some routine to group rgp.Add(func() { b = true atomic.AddInt32(&sum, 1) }) rgp.Add(func() { c = append(c, 1) atomic.AddInt32(&sum, 1) }) // run all routines and block until all routine exit rgp.Run() fmt.Println(b, c, sum) // true [1] 2
Output:
Click to show internal directories.
Click to hide internal directories.