This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Getting Started
Robert Catmull edited this page Nov 10, 2020
·
7 revisions
go get github.com/catmullet/go-workers
giving an alias helps since go-workers doesn't exactly follow conventions.
(If your using a JetBrains IDE it should automatically give it an alias)
import (
worker "github.com/catmullet/go-workers"
)
The NewWorker factory method returns a new worker.
(Method chaining can be performed on this method like calling .Work() immediately after.)
type MyWorker struct {}
func NewMyWorker() *MyWorker {
return &MyWorker{}
}
func (my *MyWorker) Work(w *goworker.Worker) error {
// work here
}
worker := worker.NewWorker(ctx, NewMyWorker(), numberOfWorkers)
Send accepts an interface. So send it anything you want.
worker.Send("Hello World")
This closes the in channel on the worker and signals to the go functions to stop.
worker.Close()
Any error that bubbles up from your worker functions will return here.
if err := worker.Wait(); err != nil {
//Handle error
}