kchanthreadpool

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 3 Imported by: 2

README

kchanthreadpool协程池

说明

  • 使用channel做任务队列的协程池
  • 每个协程仅从自身任务队列中取任务,这样可以减少锁的争抢
  • 每个任务可分配至最少任务的队列中,也可根据任务key值分配到相同的任务池,以此来保证任务的严格串行

Documentation

Overview

Package kchanthreadpool 协程池 说明 使用channel做任务队列的协程池 每个协程仅从自身任务队列中取任务,这样可以减少锁的争抢 每个任务可分配至最少任务的队列中,也可根据任务key值分配到相同的任务池,以此来保证任务的严格串行

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolHandlerIF

type PoolHandlerIF interface {
	OnError(msg string)
	OnEvent(msg string)
}

PoolHandlerIF handler for upper apps

type PoolStatus

type PoolStatus int

PoolStatus pool status

const (
	// PoolStatusClosed closed
	PoolStatusClosed PoolStatus = 0
	// PoolStatusInitialized initialized
	PoolStatusInitialized PoolStatus = 1
	// PoolStatusStarting starting
	PoolStatusStarting PoolStatus = 2
	// PoolStatusRunning running
	PoolStatusRunning PoolStatus = 3
	// PoolStatusStopping stopping
	PoolStatusStopping PoolStatus = 4
)

type Task

type Task struct {
	Data TaskJobIF
	Key  uint // key value for serial job
}

Task task for thread pool

func NewTask

func NewTask() *Task

NewTask new task object

type TaskJobIF

type TaskJobIF interface {
	Do(threadID uint)
}

TaskJobIF job interface

type ThreadPool

type ThreadPool struct {
	// contains filtered or unexported fields
}

ThreadPool thread pool

func NewThreadPool

func NewThreadPool(num uint, buffsize int, cb PoolHandlerIF) (*ThreadPool, error)

NewThreadPool new thread pool

func (*ThreadPool) AddTaskByKey

func (tp *ThreadPool) AddTaskByKey(elem *Task) (busy bool, retErr error)

AddTaskByKey add task

@return busy bool : true -- buff is full, you may need to try again @return retErr error : error

func (*ThreadPool) AddTaskByMini

func (tp *ThreadPool) AddTaskByMini(elem *Task) (busy bool, retErr error)

AddTaskByMini add task

@return busy bool : true -- buff is full, you may need to try again @return retErr error : error

func (*ThreadPool) GetTaskInfo

func (tp *ThreadPool) GetTaskInfo() string

GetTaskInfo task info

func (*ThreadPool) GetTaskSize

func (tp *ThreadPool) GetTaskSize() int

GetTaskSize task size

func (*ThreadPool) Start

func (tp *ThreadPool) Start() error

Start start

func (*ThreadPool) Stop

func (tp *ThreadPool) Stop() error

Stop stop

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL