worker

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 1 Imported by: 0

README

Usage

worker.New() starts n * Workers goroutines running func on incoming parameters sent on the returned channel.

Example

package main 

import (
	"github.com/donutloop/toolkit/worker"
	"log"
)

func main() {
	workerHandler := func(parameter interface{}) {
		v := parameter.(string)
		log.Println(v)	
	}

	queue := worker.New(2, workerHandler, 10)

	queue <- "hello"
	queue <- "world"
}

Documentation

Overview

Example
package main

import (
	"fmt"
	"time"

	"github.com/donutloop/toolkit/worker"
)

func main() {
	workerHandler := func(parameter interface{}) (interface{}, error) {
		v := parameter.(string)
		return v + " world", nil
	}

	request, response, _ := worker.New(2, workerHandler, 10)

	request <- "hello"

	<-time.After(time.Millisecond * 250)

	fmt.Println(<-response)

}
Output:

hello world

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(nWorkers uint, fn func(gt interface{}) (interface{}, error), buffer uint) (Request, Response, <-chan error)

NewWorker starts n*Workers goroutines running func on incoming parameters sent on the returned channel.

Types

type Request

type Request chan<- interface{}

type Response

type Response <-chan interface{}

Jump to

Keyboard shortcuts

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