An open API service indexing awesome lists of open source software.

https://github.com/mehditeymorian/koi

Goroutine and Worker Manager
https://github.com/mehditeymorian/koi

concurrency golang goroutine goroutine-pool goroutinemanager pool-manager synchronization

Last synced: 5 months ago
JSON representation

Goroutine and Worker Manager

Awesome Lists containing this project

README

        


Koi logo

KOI


Goroutine and Worker Manager



go version
 
license

version

# Installation
```bash
go get github.com/mehditeymorian/koi
```

# Usage
```Go
// create a pond
pond := koi.NewPond()

// create a worker
worker := koi.Worker{
ConcurrentCount: CONCURRENT_RUNNING_GOROUTINE_FOR_THIS_WORKER,
QueueSize: REQUEST_QUEUE_SIZE,
Work: func(a any) any {
// do some work
return RESULT
},
}

// register worker to a unique id
err = pond.RegisterWorker("workerID", worker)

// add job to worker
// this is non-blocking unless the queue is full.
resultChan, err := pond.AddWork("workerID", requestData)

// read results from worker
for res := range resultChan {
// do something with result
}
```
**Note**: `pond.AddJob` 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.

# Generic Version of KOI
- [Generic KOI](https://github.com/1995parham/koi) written by [Parham](https://github.com/1995parham)