koi

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

Koi logo
KOI

Goroutine and Worker Manager

go version   license version

Installation

go get github.com/mehditeymorian/koi

Usage

// 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pond

type Pond struct {
	Workers map[string]innerWorker
}

func NewPond

func NewPond() *Pond

func (*Pond) AddWork added in v1.0.1

func (p *Pond) AddWork(workerID string, request any) (chan any, error)

func (*Pond) RegisterWorker

func (p *Pond) RegisterWorker(id string, worker Worker) error

func (Pond) ResultChan

func (p Pond) ResultChan(workerID string) chan any

type Worker

type Worker struct {
	QueueSize       int
	ConcurrentCount int64
	Work            func(any) any
}

func (Worker) Validate

func (w Worker) Validate() error

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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