Skip to content
/ pool Public

🤖 pool – just a worker pool.

License

Notifications You must be signed in to change notification settings

dkharms/pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Go Report Card Test Workflow

About

Just a worker pool with regulation of the number of simultaneously running tasks and the number of maximum tasks in the queue.

Features

Ability to return calculation results.

You don't have to use closures and manage synchronization by yourself – pool will take care of it.

How To Start

  1. Declare task, which satisfies interface pool.Task:
var _ pool.Task[int] = (*DummyTask[int])(nil)

type DummyTask[T any] func() (T, error)

func (t *DummyTask[T]) Execute() (T, error) {
  return (*t)()
}

func (*DummyTask[T]) RetryAmount() int {
  return 0
}
  1. Initialize worker pool:
func PoolWithDummyTask() (int, error) {
  p := pool.New[int](1, 1)
  defer p.Close()
  p.Init()

  // …
}
  1. Enqueue you task and wait for result or error:
func PoolWithDummyTask() (int, error) {
  // …

  tw, err := p.Enqueue(&t)
  if err != nil {
      return 0, err
  }

  return tw.Result(), tw.Error()
}

What's Next

Checkout docs.

About

🤖 pool – just a worker pool.

Topics

Resources

License

Stars

Watchers

Forks

Languages