threading

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 9 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 Broadcast

type Broadcast[T any] struct {
	// contains filtered or unexported fields
}

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

func NewBroadcast

func NewBroadcast[T any](job func(ctx context.Context, data T) error, workers int) *Broadcast[T]

NewBroadcast returns a Broadcast with given job and workers.

func (Broadcast[T]) Send

func (b Broadcast[T]) Send(data T)

func (Broadcast[T]) Start

func (b Broadcast[T]) Start() error

Start starts a Broadcast.

func (Broadcast[T]) Stop

func (b Broadcast[T]) Stop() error

type PerpetualMotion

type PerpetualMotion struct {
	Debug bool
	// contains filtered or unexported fields
}

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

func NewPerpetualMotion

func NewPerpetualMotion(job func(ctx context.Context) (time.Duration, error), workers int) PerpetualMotion

NewPerpetualMotion returns a NewPerpetualMotion with given job and workers.

func (PerpetualMotion) Start

func (m PerpetualMotion) Start() error

Start starts a WorkerGroup.

func (PerpetualMotion) Stop

func (m PerpetualMotion) Stop() error

type Pool

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

func NewPool

func NewPool(size int) (*Pool, error)

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) Submit

func (p *Pool) Submit(task func(ctx context.Context))

type PoolWithFunc

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

func NewPoolWithFunc

func NewPoolWithFunc(size int, pf func(context.Context, interface{})) (pwf *PoolWithFunc, err error)

func (*PoolWithFunc) Close

func (p *PoolWithFunc) Close()

func (*PoolWithFunc) Submit

func (p *PoolWithFunc) Submit(i interface{}) error

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 Watch added in v0.0.16

type Watch[T any] struct {
	// contains filtered or unexported fields
}

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

func NewWatch added in v0.0.16

func NewWatch[T any](job func(ctx context.Context, data T) error, workers int) *Watch[T]

NewWatch returns a Watch with given job and workers.

func (Watch[T]) Send added in v0.0.16

func (b Watch[T]) Send(data T)

func (Watch[T]) Start added in v0.0.16

func (b Watch[T]) Start() error

Start starts a Broadcast.

func (Watch[T]) Stop added in v0.0.16

func (b Watch[T]) Stop() error

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