pool.go 971 B

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