Documentation ¶
Index ¶
- Constants
- type Context
- type GPool
- type NilContext
- type Task
- type TaskBox
- func (t *TaskBox[T, U, C, CT, TF]) Clone() *TaskBox[T, U, C, CT, TF]
- func (t *TaskBox[T, U, C, CT, TF]) ConstArgs() C
- func (t *TaskBox[T, U, C, CT, TF]) Done()
- func (t *TaskBox[T, U, C, CT, TF]) Finish()
- func (t *TaskBox[T, U, C, CT, TF]) GetContextFunc() TF
- func (t *TaskBox[T, U, C, CT, TF]) GetResultCh() chan U
- func (t *TaskBox[T, U, C, CT, TF]) GetStatus() int32
- func (t *TaskBox[T, U, C, CT, TF]) GetTaskCh() chan Task[T]
- func (t *TaskBox[T, U, C, CT, TF]) SetStatus(s int32)
- func (t *TaskBox[T, U, C, CT, TF]) TaskID() uint64
- type TaskController
- type TaskManager
- func (t *TaskManager[T, U, C, CT, TF]) AddSubTask(taskID uint64, task *TaskBox[T, U, C, CT, TF])
- func (t *TaskManager[T, U, C, CT, TF]) DeleteTask(taskID uint64)
- func (t *TaskManager[T, U, C, CT, TF]) Downclock(capacity int)
- func (t *TaskManager[T, U, C, CT, TF]) ExitSubTask(taskID uint64)
- func (t *TaskManager[T, U, C, CT, TF]) GetOriginConcurrency() int32
- func (t *TaskManager[T, U, C, CT, TF]) Overclock(capacity int) (tid uint64, task *TaskBox[T, U, C, CT, TF])
- func (t *TaskManager[T, U, C, CT, TF]) RegisterTask(taskID uint64, concurrency int32)
- func (t *TaskManager[T, U, C, CT, TF]) Running(taskID uint64) int32
- func (t *TaskManager[T, U, C, CT, TF]) StopTask(taskID uint64)
- type TaskStatusContainer
Constants ¶
const ( // PendingTask is a task waiting to start. PendingTask int32 = iota // RunningTask is a task running. RunningTask // StopTask is a stop task. StopTask )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context[T any] interface { GetContext() T }
Context is a interface that can be used to create a context.
type GPool ¶
type GPool[T any, U any, C any, CT any, TF Context[CT]] interface { Tune(size int32) DeleteTask(id uint64) StopTask(id uint64) }
GPool is a goroutine pool.
type NilContext ¶
type NilContext struct{}
NilContext is to create a nil as context
func (NilContext) GetContext ¶
func (NilContext) GetContext() any
GetContext is to get a nil as context
type TaskBox ¶
type TaskBox[T any, U any, C any, CT any, TF Context[CT]] struct { // contains filtered or unexported fields }
TaskBox is a box which contains all info about pool task.
func NewTaskBox ¶
func NewTaskBox[T any, U any, C any, CT any, TF Context[CT]](constArgs C, contextFunc TF, wg *sync.WaitGroup, taskCh chan Task[T], resultCh chan U, taskID uint64) TaskBox[T, U, C, CT, TF]
NewTaskBox is to create a task box for pool.
func (*TaskBox[T, U, C, CT, TF]) ConstArgs ¶
func (t *TaskBox[T, U, C, CT, TF]) ConstArgs() C
ConstArgs is to get the const args.
func (*TaskBox[T, U, C, CT, TF]) Done ¶
func (t *TaskBox[T, U, C, CT, TF]) Done()
Done is to set the pooltask status to complete.
func (*TaskBox[T, U, C, CT, TF]) Finish ¶
func (t *TaskBox[T, U, C, CT, TF]) Finish()
Finish is to set the TaskBox finish status.
func (*TaskBox[T, U, C, CT, TF]) GetContextFunc ¶
func (t *TaskBox[T, U, C, CT, TF]) GetContextFunc() TF
GetContextFunc is to get context func.
func (*TaskBox[T, U, C, CT, TF]) GetResultCh ¶
func (t *TaskBox[T, U, C, CT, TF]) GetResultCh() chan U
GetResultCh is to get result channel
type TaskController ¶
type TaskController[T any, U any, C any, CT any, TF Context[CT]] struct { // contains filtered or unexported fields }
TaskController is a controller that can control or watch the pool.
func NewTaskController ¶
func NewTaskController[T any, U any, C any, CT any, TF Context[CT]](p GPool[T, U, C, CT, TF], taskID uint64, productExitCh chan struct{}, wg *sync.WaitGroup, inputCh chan Task[T], resultCh chan U) TaskController[T, U, C, CT, TF]
NewTaskController create a controller to deal with pooltask's status.
func (*TaskController[T, U, C, CT, TF]) Stop ¶
func (t *TaskController[T, U, C, CT, TF]) Stop()
Stop is to send stop command to the task. But you still need to wait the task to stop.
func (*TaskController[T, U, C, CT, TF]) TaskID ¶
func (t *TaskController[T, U, C, CT, TF]) TaskID() uint64
TaskID is to get the task id.
func (*TaskController[T, U, C, CT, TF]) Wait ¶
func (t *TaskController[T, U, C, CT, TF]) Wait()
Wait is to wait the pool task to stop.
type TaskManager ¶
type TaskManager[T any, U any, C any, CT any, TF Context[CT]] struct { // contains filtered or unexported fields }
TaskManager is a manager that can control or watch the pool.
func NewTaskManager ¶
func NewTaskManager[T any, U any, C any, CT any, TF Context[CT]](c int32) TaskManager[T, U, C, CT, TF]
NewTaskManager create a new pool task manager.
func (*TaskManager[T, U, C, CT, TF]) AddSubTask ¶
func (t *TaskManager[T, U, C, CT, TF]) AddSubTask(taskID uint64, task *TaskBox[T, U, C, CT, TF])
AddSubTask AddTask add a task to the manager.
func (*TaskManager[T, U, C, CT, TF]) DeleteTask ¶
func (t *TaskManager[T, U, C, CT, TF]) DeleteTask(taskID uint64)
DeleteTask delete a task from the manager.
func (*TaskManager[T, U, C, CT, TF]) Downclock ¶
func (t *TaskManager[T, U, C, CT, TF]) Downclock(capacity int)
Downclock is to decrease the concurrency of pool.
func (*TaskManager[T, U, C, CT, TF]) ExitSubTask ¶
func (t *TaskManager[T, U, C, CT, TF]) ExitSubTask(taskID uint64)
ExitSubTask is to exit a task, and it will decrease the count of running pooltask.
func (*TaskManager[T, U, C, CT, TF]) GetOriginConcurrency ¶
func (t *TaskManager[T, U, C, CT, TF]) GetOriginConcurrency() int32
GetOriginConcurrency return the concurrency of the pool at the init.
func (*TaskManager[T, U, C, CT, TF]) Overclock ¶
func (t *TaskManager[T, U, C, CT, TF]) Overclock(capacity int) (tid uint64, task *TaskBox[T, U, C, CT, TF])
Overclock is to increase the concurrency of pool.
func (*TaskManager[T, U, C, CT, TF]) RegisterTask ¶
func (t *TaskManager[T, U, C, CT, TF]) RegisterTask(taskID uint64, concurrency int32)
RegisterTask register a task to the manager.
func (*TaskManager[T, U, C, CT, TF]) Running ¶
func (t *TaskManager[T, U, C, CT, TF]) Running(taskID uint64) int32
Running return the count of running job in this task.
func (*TaskManager[T, U, C, CT, TF]) StopTask ¶
func (t *TaskManager[T, U, C, CT, TF]) StopTask(taskID uint64)
StopTask is to stop a task by TaskID.