threading

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 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 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 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 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