https://github.com/1995parham/koi
Generic Goroutine and Worker Manager based on https://github.com/mehditeymorian/koi
https://github.com/1995parham/koi
Last synced: 9 months ago
JSON representation
Generic Goroutine and Worker Manager based on https://github.com/mehditeymorian/koi
- Host: GitHub
- URL: https://github.com/1995parham/koi
- Owner: 1995parham
- License: apache-2.0
- Created: 2022-10-15T07:19:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-30T04:33:54.000Z (over 2 years ago)
- Last Synced: 2025-04-12T19:53:29.855Z (9 months ago)
- Language: Go
- Size: 86.9 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

KOI
Generic Goroutine and Worker Manager
## Installation
You can add **Koi** into your project as follows:
```bash
go get github.com/1995parham/koi
```
## Usage
In Koi you first register a worker on a Pond then push your inputs.
Your worker has concurrency configuration for handling inputs.
Worker has generic interface. The first generic parameter is an input rype and the second parameter
is an output parameter.
```go
package main
import (
"log"
"sync"
"time"
"github.com/1995parham/koi"
)
func main() {
pond := koi.NewPond[int, koi.NoReturn]()
var wg sync.WaitGroup
printer := func(a int) koi.NoReturn {
time.Sleep(1 * time.Second)
log.Println(a)
wg.Done()
return koi.None
}
// nolint: gomnd
printWorker := koi.MustNewWoker(printer, 2, 10)
pond.MustRegisterWorker("printer", printWorker)
for i := 0; i < 10; i++ {
wg.Add(1)
if _, err := pond.AddWork("printer", i); err != nil {
log.Printf("error while adding job: %s\n", err)
}
}
wg.Wait()
log.Println("all job added")
}
```
**Note**: `pond.AddWork` is non-blocking unless worker queue is full.
## Terminology
- **Koi**: Koi is an informal name for the colored variants of C. rubrofuscus kept for ornamental purposes.
- **Pond**: an area of water smaller than a lake, often artificially made.