Documentation ¶
Index ¶
- type GoPool
- func (g *GoPool) NewGroupContext() (*pond.TaskGroupWithContext, context.Context)
- func (g *GoPool) NewTaskGroup() *pond.TaskGroup
- func (g *GoPool) PoolStats() PoolStat
- func (g *GoPool) PrintPoolStats()
- func (g *GoPool) PrometheusHandler()
- func (g *GoPool) Stop() context.Context
- func (g *GoPool) StopAndWait()
- func (g *GoPool) StopAndWaitFor(deadline time.Duration)
- func (g *GoPool) Stopped() bool
- func (g *GoPool) Submit(fn func())
- type PoolStat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoPool ¶
type GoPool struct {
// contains filtered or unexported fields
}
func NewContextPool ¶
Create a context that will be cancelled Tasks being processed will continue until they finish, but queued tasks are cancelled.
func NewDynamicSizePool ¶
Create a buffered (non-blocking) pool that can scale up to maxWorkers workers
and has a buffer capacity of maxCapacity tasks
创建一个缓冲(非阻塞)池,最多可扩展到maxWorkers个Worker,缓冲容量为maxCapacity个任务(大于这个会阻塞等待提交)
func NewFixedSizePool ¶
使用固定数量的Worker创建一个无缓冲(阻塞)池,提交任务等待
func (*GoPool) NewGroupContext ¶
func (g *GoPool) NewGroupContext() (*pond.TaskGroupWithContext, context.Context)
group, ctx := pool.GroupContext(context.Background())
group.Submit(func() error { req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) resp, err := http.DefaultClient.Do(req) if err == nil { resp.Body.Close() } return err })
Wait for all fn to complete.
err := group.Wait() if err != nil { fmt.Printf("Failed to Error: %v", err) } else { fmt.Println("Successfully all") }
Create a task group associated to a context
func (*GoPool) NewTaskGroup ¶
Create a task group group := pool.Group() // Submit a group of related tasks for i := 0; i < 20; i++ { n := i group.Submit(func() { fmt.Printf("Running group task #%d\n", n) }) } // Wait for all tasks in the group to complete group.Wait() }
func (*GoPool) PrintPoolStats ¶
func (g *GoPool) PrintPoolStats()
func (*GoPool) PrometheusHandler ¶
func (g *GoPool) PrometheusHandler()
func (*GoPool) Stop ¶ added in v1.2.6
Stop会导致此池停止接受新任务,并向所有workers发出退出信号。 worker正在执行的任务将一直持续到完成(除非流程终止)。 队列中的任务将不会被执行。 此方法返回一个上下文对象,当池完全停止时,该对象将被取消。
func (*GoPool) StopAndWait ¶
func (g *GoPool) StopAndWait()
func (*GoPool) StopAndWaitFor ¶ added in v1.2.6
StopAndWaitFor停止此池并等待队列中的所有任务完成 或者达到给定的截止日期,以先到者为准。