qsants

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Options(
	fx.Provide(
		fx.Annotate(
			func(threadCount int, configs *ants.Options, logger *zap.Logger, lc fx.Lifecycle) (*ants.Pool, error) {
				if configs == nil {
					return nil, nil
				}
				p, _ := newPool(threadCount, ants.WithOptions(*configs))

				lc.Append(fx.Hook{
					OnStart: func(ctx context.Context) error {
						if logger != nil {
							logger.Info("Thread pool", zap.Int("Number of threads", threadCount))
						} else {
							log.Printf("Thread pool count=%v\n", threadCount)
						}
						return nil
					},
					OnStop: func(ctx context.Context) error {
						if logger != nil {
							logger.Info("Stopping thread pool")
						} else {
							log.Println("Stopping thread pool")
						}
						if !p.IsClosed() {
							p.Release()
						}
						defer ants.Release()
						return nil
					},
				})
				return p, nil
			},
			fx.ParamTags(
				`name:"threadCount" optional:"true"`,
				`optional:"true"`,
				`optional:"true"`,
			),
		),
	),
)

Functions

func NewLogger

func NewLogger(logger *zap.SugaredLogger) *loggerAdapter

func NewLoggerWithDefault

func NewLoggerWithDefault(def *log.Logger) *defLoggerAdapter

func ProvideThreadPool

func ProvideThreadPool(cfg qsconfig.ConfigType[*ants.Options], count int) fx.Option

Provides the thread pool manager the configurations.

To use this:

 var Module = fx.Options(
		qsants.ProvideThreadPool(&qsants.DefaultPoolConfigs{})
 )

or you can create a customized version by implementing:

qsconfig.ConfigType[*ants.Options]

Types

type DefaultPoolConfigs

type DefaultPoolConfigs struct{}

Default configurations for ants.

Memory preallocation is disabled and unused routines are swept after an hour

func (*DefaultPoolConfigs) Config

func (s *DefaultPoolConfigs) Config() (*ants.Options, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳