github.com/gregpr07/bsc@v1.1.2/common/gopool/pool.go (about)

     1  package gopool
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/panjf2000/ants/v2"
     7  )
     8  
     9  var (
    10  	// Init a instance pool when importing ants.
    11  	defaultPool, _ = ants.NewPool(ants.DefaultAntsPoolSize, ants.WithExpiryDuration(10*time.Second))
    12  )
    13  
    14  // Logger is used for logging formatted messages.
    15  type Logger interface {
    16  	// Printf must have the same semantics as log.Printf.
    17  	Printf(format string, args ...interface{})
    18  }
    19  
    20  // Submit submits a task to pool.
    21  func Submit(task func()) error {
    22  	return defaultPool.Submit(task)
    23  }
    24  
    25  // Running returns the number of the currently running goroutines.
    26  func Running() int {
    27  	return defaultPool.Running()
    28  }
    29  
    30  // Cap returns the capacity of this default pool.
    31  func Cap() int {
    32  	return defaultPool.Cap()
    33  }
    34  
    35  // Free returns the available goroutines to work.
    36  func Free() int {
    37  	return defaultPool.Free()
    38  }
    39  
    40  // Release Closes the default pool.
    41  func Release() {
    42  	defaultPool.Release()
    43  }
    44  
    45  // Reboot reboots the default pool.
    46  func Reboot() {
    47  	defaultPool.Reboot()
    48  }