https://github.com/kaatinga/luna
thread safe worker pool
https://github.com/kaatinga/luna
help-wanted thread-safe worker worker-pool
Last synced: 5 months ago
JSON representation
thread safe worker pool
- Host: GitHub
- URL: https://github.com/kaatinga/luna
- Owner: kaatinga
- License: mit
- Created: 2023-06-18T20:43:02.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-06T20:50:25.000Z (almost 2 years ago)
- Last Synced: 2024-07-06T21:47:36.443Z (almost 2 years ago)
- Topics: help-wanted, thread-safe, worker, worker-pool
- Language: Go
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Support: supported_types.go
Awesome Lists containing this project
README
[](https://github.com/kaatinga/luna/actions/workflows/test.yml)
[](https://codecov.io/gh/kaatinga/luna)
[](https://github.com/luna/luna/actions?query=workflow%3Alinter)
[](https://github.com/kaatinga/luna/blob/main/LICENSE)
[](https://github.com/luna/strconv/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)
# Luna
Luna is a flexible and generic worker pool implementation in Go, designed to manage and orchestrate workers efficiently. It supports generic types for keys and workers, allowing for a wide range of applications. Workers in the pool can be started, stopped, and have operations executed upon them, providing a robust framework for concurrent task execution.
## Features
- Generic implementation supporting any key and worker types.
- Thread-safe operations to add, delete, and manipulate workers.
- Error handling for start and stop operations of workers.
## Installation
To install Luna, you need a working Go environment. Luna can be installed using `go get`:
```sh
go get github.com/kaatinga/luna
```
## Usage
Here's a simple example of how to use Luna:
```go
package main
import (
"fmt"
"github.com/kaatinga/luna"
)
type myWorker struct{}
func (myWorker) Start() error {
fmt.Println("Worker started")
return nil
}
func (myWorker) Stop() error {
fmt.Println("Worker stopped")
return nil
}
func main() {
pool := luna.NewWorkerPool[string, myWorker]()
if err := pool.Add("worker1", myWorker{}); err != nil {
fmt.Printf("Error adding worker: %v\n", err)
}
pool.Do("worker1", func(item *luna.Item[string, myWorker]) {
fmt.Println("Executing operation on worker")
})
if err := pool.Delete("worker1"); err != nil {
fmt.Printf("Error removing worker: %v\n", err)
}
}
```
## Testing
To run the tests for Luna, navigate to the package directory and use the Go tool:
```sh
go test ./...
```
## Contributing
Contributions are welcome! Please feel free to submit a pull request or open issues to discuss potential improvements or features.
## License
[MIT License](LICENSE)