Skip to content

unixander/workerpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI workflow

Workerpool

This is an implementation of pool of workers, that does not repeat execution of executor function if the previous call has not been completed yet. When the request finishes all registered listeners will get the result of function execution.

Example of usage

// context to stop worker
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// create pool of workers with executor function
pool := workerpool.NewWorkerPool[int, int](
  func(ctx context.Context, value int) (int, error) {
   return value * value, nil
  },
)

// start pool
go pool.Run(ctx)

// submit task
pool.Submit(ctx, i, func(ctx context.Context, value int, err error) {
    fmt.Println("result =", value)
})

// trigger pool stop
cancel()

// wait for all the workers to terminate gracefully
pool.Join(context.Background())

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published