Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Go = func(f func()) {
globalG.Go(f)
}
Go 暴露到外界到可控写成方法
Functions ¶
This section is empty.
Types ¶
type GoRoutine ¶
type GoRoutine struct {
// contains filtered or unexported fields
}
GoRoutine 协程池
func New ¶
New 创建一个协程池
limit: 协程池限制 multiple: 缓冲区大小
Example ¶
package main
import (
"context"
"fmt"
"time"
goroutine "github.com/aide-family/moon/pkg/util/go"
)
func main() {
limit := 2
multiple := 2
g := goroutine.New(limit, multiple)
ctx := context.Background()
if err := g.Start(ctx); err != nil {
panic(err)
}
for i := range 20 {
item := i
goroutine.Go(func() {
time.Sleep(100 * time.Millisecond)
fmt.Println("msg: ", item)
})
}
time.Sleep(time.Second * 4)
if err := g.Stop(ctx); err != nil {
panic(err)
}
}
Output:
Click to show internal directories.
Click to hide internal directories.