-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88e264b
commit 1706fd3
Showing
1 changed file
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
# koi | ||
Goroutine Pool and Worker Manager | ||
<h1 align="center"> | ||
<img alt="Koi logo" src="asset/logo.webp" width="500px"/><br/> | ||
KOI | ||
</h1> | ||
<p align="center">Goroutine and Worker Manager</p> | ||
|
||
<p align="center"> | ||
<a href="https://pkg.go.dev/github.com/mehditeymorian/koi/v3?tab=doc"target="_blank"> | ||
<img src="https://img.shields.io/badge/Go-1.18+-00ADD8?style=for-the-badge&logo=go" alt="go version" /> | ||
</a> | ||
<img src="https://img.shields.io/badge/license-apache_2.0-red?style=for-the-badge&logo=none" alt="license" /> | ||
|
||
<img src="https://img.shields.io/badge/Version-1.0.0-informational?style=for-the-badge&logo=none" alt="version" /> | ||
</p> | ||
|
||
# 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.AddJob("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. | ||
|