threading

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT 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 GoSafe0 added in v0.1.0

func GoSafe0[Arg0 any](fn func(arg0 Arg0), arg0 Arg0)

func GoSafe1 added in v0.1.0

func GoSafe1[Arg0 any, Arg1 any](fn func(arg0 Arg0, arg1 Arg1), arg0 Arg0, arg1 Arg1)

func GoSafeCtx added in v0.1.0

func GoSafeCtx(ctx context.Context, fn func())

GoSafeCtx runs the given fn using another goroutine, recovers if fn panics with ctx.

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.

func RunSafe0 added in v0.1.0

func RunSafe0[Arg0 any](fn func(arg0 Arg0), arg0 Arg0)

func RunSafe1 added in v0.1.0

func RunSafe1[Arg0 any, Arg1 any](fn func(arg0 Arg0, arg1 Arg1), arg0 Arg0, arg1 Arg1)

func RunSafeCtx added in v0.1.0

func RunSafeCtx(ctx context.Context, fn func())

RunSafeCtx runs the given fn, recovers if fn panics with ctx.

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 RoutineGroup0 added in v0.1.0

type RoutineGroup0[Arg0 any] struct {
	// contains filtered or unexported fields
}

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

func NewRoutineGroup0 added in v0.1.0

func NewRoutineGroup0[Arg0 any]() *RoutineGroup0[Arg0]

NewRoutineGroup0 returns a RoutineGroup.

func (*RoutineGroup0[Arg0]) Run added in v0.1.0

func (g *RoutineGroup0[Arg0]) 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 (*RoutineGroup0[Arg0]) Run0 added in v0.1.0

func (g *RoutineGroup0[Arg0]) Run0(fn func(arg0 Arg0), arg0 Arg0)

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

func (*RoutineGroup0[Arg0]) RunSafe added in v0.1.0

func (g *RoutineGroup0[Arg0]) 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 (*RoutineGroup0[Arg0]) RunSafe0 added in v0.1.0

func (g *RoutineGroup0[Arg0]) RunSafe0(fn func(arg0 Arg0), arg0 Arg0)

RunSafe0 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 (*RoutineGroup0[Arg0]) Wait added in v0.1.0

func (g *RoutineGroup0[Arg0]) Wait()

Wait waits all running functions to be done.

type RoutineGroup1 added in v0.1.0

type RoutineGroup1[Arg0 any, Arg1 any] struct {
	// contains filtered or unexported fields
}

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

func NewRoutineGroup1 added in v0.1.0

func NewRoutineGroup1[Arg0 any, Arg1 any]() *RoutineGroup1[Arg0, Arg1]

NewRoutineGroup1 returns a RoutineGroup.

func (*RoutineGroup1[Arg0, Arg1]) Run added in v0.1.0

func (g *RoutineGroup1[Arg0, Arg1]) 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 (*RoutineGroup1[Arg0, Arg1]) Run1 added in v0.1.0

func (g *RoutineGroup1[Arg0, Arg1]) Run1(fn func(arg0 Arg0, arg1 Arg1), arg0 Arg0, arg1 Arg1)

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

func (*RoutineGroup1[Arg0, Arg1]) RunSafe added in v0.1.0

func (g *RoutineGroup1[Arg0, Arg1]) 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 (*RoutineGroup1[Arg0, Arg1]) RunSafe1 added in v0.1.0

func (g *RoutineGroup1[Arg0, Arg1]) RunSafe1(fn func(arg0 Arg0, arg1 Arg1), arg0 Arg0, arg1 Arg1)

RunSafe1 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 (*RoutineGroup1[Arg0, Arg1]) Wait added in v0.1.0

func (g *RoutineGroup1[Arg0, Arg1]) Wait()

Wait waits all running functions to be done.

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