github.com/zly-app/zapp@v1.3.3/core/component.gpool.go (about)

     1  /*
     2  -------------------------------------------------
     3     Author :       zlyuancn
     4     date:         2021/3/19
     5     Description :
     6  -------------------------------------------------
     7  */
     8  
     9  package core
    10  
    11  type IGPools interface {
    12  	// 获取gpool
    13  	GetGPool(name ...string) IGPool
    14  	// 关闭
    15  	Close()
    16  }
    17  
    18  type IGPool interface {
    19  	// 异步执行
    20  	Go(fn func() error, callback func(err error))
    21  	// 同步执行
    22  	GoSync(fn func() error) (result error)
    23  	// 尝试异步执行, 如果任务队列已满则返回false
    24  	TryGo(fn func() error, callback func(err error)) (ok bool)
    25  	// 尝试同步执行, 如果任务队列已满则返回false
    26  	TryGoSync(fn func() error) (result error, ok bool)
    27  	// 执行等待所有函数完成
    28  	GoAndWait(fn ...func() error) error
    29  	// 等待队列中所有的任务结束
    30  	Wait()
    31  	// 关闭, 命令所有没有收到任务的工人立即停工, 收到任务的工人完成当前任务后停工, 不管任务队列是否清空
    32  	Close()
    33  }