coroutine

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go(printf func(formatter string, args ...any), fn func(args ...any), args ...any)

谨慎使用,仅适用旁路分支不需要对panic做处理的场景下 考虑fn是事件循环模型,由于panic协程退出了,主协程没有感知还在运行,实际上svr已经无法提供服务了

func GoAndRetry

func GoAndRetry(printf func(formatter string, args ...any), retryDelay int, fn func(args ...any) error, args ...any)

如果我们有定时任务需要执行,同时我们不希望失败就退出,而是要继续执行,封装co.GoAndRetry接口

func GoAndWait

func GoAndWait(fns ...func() error) error

1. 多协程并发执行时,一个协程抛出panic会导致所有协程全部退出,一个协程的panic只能该协程调用recover捕获,所以每个协程都要执行defer func() { recover() }() 2. 如果我们有批量的任务需要执行,肯定通过并发调用来提高性能,同时我们不希望其中一个调用失败就导致所有的任务都退出,而是要继续执行完其它的任务,封装co.GoAndWait接口

Types

type Pool

type Pool struct {
	*ants.Pool
	// contains filtered or unexported fields
}

func NewPool

func NewPool(poolSize int, taskSize int, printf func(formatter string, args ...any)) (*Pool, error)

func (*Pool) Release added in v0.1.3

func (pool *Pool) Release()

func (*Pool) Submit added in v0.1.3

func (pool *Pool) Submit(task func()) error

type PoolFunc added in v0.3.0

type PoolFunc struct {
	*ants.PoolWithFunc
	// contains filtered or unexported fields
}

func NewPoolFunc added in v0.3.0

func NewPoolFunc(poolSize int, taskSize int, printf func(formatter string, args ...any), task func(any)) (*PoolFunc, error)

func (*PoolFunc) Invoke added in v0.3.0

func (pool *PoolFunc) Invoke(arg any) error

func (*PoolFunc) Release added in v0.3.0

func (pool *PoolFunc) Release()

Jump to

Keyboard shortcuts

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