github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/net/pool/goroutine/goroutine.go (about)

     1  package goroutine
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/panjf2000/ants/v2"
     7  )
     8  
     9  const (
    10  	// DefaultAntsPoolSize sets up the capacity of worker pool, 256 * 1024.
    11  	DefaultAntsPoolSize = 1 << 18
    12  
    13  	// ExpiryDuration is the interval time to clean up those expired workers.
    14  	ExpiryDuration = 10 * time.Second
    15  
    16  	// Nonblocking decides what to do when submitting a new job to a full worker pool: waiting for a available worker
    17  	// or returning nil directly.
    18  	Nonblocking = true
    19  )
    20  
    21  func init() {
    22  	// It releases the default pool from ants.
    23  	ants.Release()
    24  }
    25  
    26  // Pool is the alias of ants.Pool.
    27  type Pool = ants.Pool
    28  
    29  // Default instantiates a non-blocking *WorkerPool with the capacity of DefaultAntsPoolSize.
    30  func Default() *Pool {
    31  	options := ants.Options{ExpiryDuration: ExpiryDuration, Nonblocking: Nonblocking}
    32  	defaultAntsPool, _ := ants.NewPool(DefaultAntsPoolSize, ants.WithOptions(options))
    33  	return defaultAntsPool
    34  }