workerpool

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 3 Imported by: 2

README

Workerpool Library for Go

A simple and efficient worker pool implementation in Go for concurrent task execution.

Features

  • Easy-to-use API for managing worker pools.
  • Static sizing of the pool irrespective of workload.
  • Flexible configuration options for controlling pool behavior.
  • Optimized for performance.

Installation

go get github.com/veerakumarak/go-workerpool

Usage

package main import ( "fmt" "github.com/veerakumarak/go-workerpool" ) func main() { // Create a new worker pool with 5 workers. pool := workerpool.New("default-pool", 10, 100) // Add tasks to the pool. for i := 0; i < 10; i++ { taskID := i pool.Submit(func() { fmt.Printf("Task %d is being processed\n", taskID) }) } // Wait for all tasks to complete and pool to be shutdown. pool.Shutdown() fmt.Println("All tasks have completed.") }

Configuration

The worker pool can be configured with the following options:

  • MaxWorkers: Maximum number of workers in the pool.
  • MaxQueueSize: Maximum size of the task queue.

Example:

poolName := "default-pool" maxWorkers := 10 maxQueueSize := 100 pool := workerpool.New(poolName, maxWorkers, maxQueueSize)

Contributing

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IWorkerPool

type IWorkerPool interface {
	Start()
	Submit(Task) error
	Shutdown()
}

func New

func New(name string, maxWorkers int, queueSize int) IWorkerPool

type Task

type Task func()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL