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 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)
Click to show internal directories.
Click to hide internal directories.