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
@@ -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` 运行时的流程图如下
@@ -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