thread

package
v2.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoSafe

func GoSafe(fn func())

GoSafe runs the given fn using another goroutine, recovers if fn panics.

func RoutineId

func RoutineId() uint64

RoutineId is only for debug, never use it in production.

func RunSafe

func RunSafe(fn func())

RunSafe runs the given fn, recovers if fn panics.

Types

type RoutineGroup

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

A RoutineGroup is used to group goroutines together and all wait all goroutines to be done.

func NewRoutineGroup

func NewRoutineGroup() *RoutineGroup

NewRoutineGroup returns a RoutineGroup.

func (*RoutineGroup) Run

func (g *RoutineGroup) Run(fn func())

Run runs the given fn in RoutineGroup. Don't reference the variables from outside, because outside variables can be changed by other goroutines

func (*RoutineGroup) RunSafe

func (g *RoutineGroup) RunSafe(fn func())

RunSafe runs the given fn in RoutineGroup, and avoid panics. Don't reference the variables from outside, because outside variables can be changed by other goroutines

func (*RoutineGroup) Wait

func (g *RoutineGroup) Wait()

Wait waits all running functions to be done.

type TaskRunner

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

A TaskRunner is used to control the concurrency of goroutines.

func NewTaskRunner

func NewTaskRunner(concurrency int) *TaskRunner

NewTaskRunner returns a TaskRunner.

func (*TaskRunner) Schedule

func (rp *TaskRunner) Schedule(task func())

Schedule schedules a task to run under concurrency control.

type WorkerGroup

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

A WorkerGroup is used to run given number of workers to process jobs.

func NewWorkerGroup

func NewWorkerGroup(job func(), workers int) WorkerGroup

NewWorkerGroup returns a WorkerGroup with given job and workers.

func (WorkerGroup) Start

func (wg WorkerGroup) Start()

Start starts a WorkerGroup.

Jump to

Keyboard shortcuts

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