wrapper

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(wrapType WrapType, c constructor)

Register register wrapper

Types

type Option

type Option func(o *Options)

Options optional function

func WithBufCap

func WithBufCap(c int) Option

WithBufCap set buf cap

func WithRecover

func WithRecover(recoveryFunc func()) Option

WithRecover set recover func

type Options

type Options struct {
	BufCap       int
	RecoveryFunc func()
}

Option wrapper option

type WrapType

type WrapType int

WrapType wrap type

const (
	// WgWrapper waitGroup wrapper
	WgWrapper WrapType = iota
	// ChWrapper chan wrapper
	ChWrapper
)

type Wrapper

type Wrapper interface {
	// Wrap exec func in goroutine without recover catch
	Wrap(fn func())

	// WrapWithRecover safely execute func in goroutine
	WrapWithRecover(fn func())

	// Wait this func wait all goroutine finish
	Wait()
}

Wrapper wrap goroutine to run

func New

func New(wrapType WrapType, opts ...Option) Wrapper

New create wrapper interface

func NewChanWrapper

func NewChanWrapper(opts ...Option) Wrapper

NewChanWrapper create wrapChanImpl entity If the wrapper using the chan method needs to specify the number of goroutines to be executed,the WithBufCap method needs to be called. Otherwise, after the Wait method is executed, some goroutines will exit without execution.

func NewWgWrapper

func NewWgWrapper(opts ...Option) Wrapper

NewWgWrapper create wrapper entity

Jump to

Keyboard shortcuts

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