Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrSizeLessZero = errors.New("size less than 0")
Functions ¶
This section is empty.
Types ¶
type RoutineGroup ¶
type RoutineGroup struct {
// contains filtered or unexported fields
}
RoutineGroup 协程组,是sync.WaitGroup的增强版本.
func NewRoutineGroup ¶
func NewRoutineGroup(size uint) *RoutineGroup
NewRoutineGroup 协程组,控制协程总数量.
Example ¶
package main
import (
"fmt"
"github.com/xuender/kit/sync"
)
func main() {
group := sync.NewRoutineGroup(3)
for i := 0; i < 5; i++ {
group.Add(1)
go func() {
defer group.Done()
fmt.Println("x")
}()
}
group.Wait()
}
Output: x x x x x
func (*RoutineGroup) Inc ¶
func (p *RoutineGroup) Inc()
Inc 加1.
Example ¶
package main
import (
"fmt"
"github.com/xuender/kit/sync"
)
func main() {
group := sync.NewRoutineGroup(3)
for i := 0; i < 5; i++ {
group.Inc()
go func() {
defer group.Done()
fmt.Println("x")
}()
}
group.Wait()
}
Output: x x x x x
Click to show internal directories.
Click to hide internal directories.