From 617c89699a3487e9f0b7339fb2b3fe45f312aa71 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 7 Oct 2019 20:53:23 +0800 Subject: [PATCH] Renew the functional options in READMEs --- README.md | 12 +++++++++++- README_ZH.md | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 991160e..1693a46 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Library `ants` implements a goroutine pool with fixed capacity, managing and rec - 1.12.x - 1.13.x -## ants works as the flowing flowchart +## `ants` works as the flowing flowchart

ants @@ -179,6 +179,10 @@ func main() { ## Functional options for ants pool ```go +// Option represents the optional function. +type Option func(opts *Options) + +// Options contains all options which will be applied when instantiating a ants pool. type Options struct { // ExpiryDuration set the expired time (second) of every worker. ExpiryDuration time.Duration @@ -200,36 +204,42 @@ type Options struct { PanicHandler func(interface{}) } +// WithOptions accepts the whole options config. func WithOptions(options Options) Option { return func(opts *Options) { *opts = options } } +// WithExpiryDuration sets up the interval time of cleaning up goroutines. func WithExpiryDuration(expiryDuration time.Duration) Option { return func(opts *Options) { opts.ExpiryDuration = expiryDuration } } +// WithPreAlloc indicates whether it should malloc for workers. func WithPreAlloc(preAlloc bool) Option { return func(opts *Options) { opts.PreAlloc = preAlloc } } +// WithMaxBlockingTasks sets up the maximum number of goroutines that are blocked when it reaches the capacity of pool. func WithMaxBlockingTasks(maxBlockingTasks int) Option { return func(opts *Options) { opts.MaxBlockingTasks = maxBlockingTasks } } +// WithNonblocking indicates that pool will return nil when there is no available workers. func WithNonblocking(nonblocking bool) Option { return func(opts *Options) { opts.Nonblocking = nonblocking } } +// WithPanicHandler sets up panic handler. func WithPanicHandler(panicHandler func(interface{})) Option { return func(opts *Options) { opts.PanicHandler = panicHandler diff --git a/README_ZH.md b/README_ZH.md index 3c853ca..a052deb 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -36,7 +36,7 @@ A goroutine pool for Go - 1.12.x - 1.13.x -## ants 运行时的流程图如下 +## `ants` 运行时的流程图如下

ants @@ -179,6 +179,10 @@ func main() { ## Pool 配置 ```go +// Option represents the optional function. +type Option func(opts *Options) + +// Options contains all options which will be applied when instantiating a ants pool. type Options struct { // ExpiryDuration set the expired time (second) of every worker. ExpiryDuration time.Duration @@ -200,36 +204,42 @@ type Options struct { PanicHandler func(interface{}) } +// WithOptions accepts the whole options config. func WithOptions(options Options) Option { return func(opts *Options) { *opts = options } } +// WithExpiryDuration sets up the interval time of cleaning up goroutines. func WithExpiryDuration(expiryDuration time.Duration) Option { return func(opts *Options) { opts.ExpiryDuration = expiryDuration } } +// WithPreAlloc indicates whether it should malloc for workers. func WithPreAlloc(preAlloc bool) Option { return func(opts *Options) { opts.PreAlloc = preAlloc } } +// WithMaxBlockingTasks sets up the maximum number of goroutines that are blocked when it reaches the capacity of pool. func WithMaxBlockingTasks(maxBlockingTasks int) Option { return func(opts *Options) { opts.MaxBlockingTasks = maxBlockingTasks } } +// WithNonblocking indicates that pool will return nil when there is no available workers. func WithNonblocking(nonblocking bool) Option { return func(opts *Options) { opts.Nonblocking = nonblocking } } +// WithPanicHandler sets up panic handler. func WithPanicHandler(panicHandler func(interface{})) Option { return func(opts *Options) { opts.PanicHandler = panicHandler