Always manage your goroutines

func Invoke(ctx context.Context, job *api.Job) (*pb.Empty, error) {
go func() {
if err := ma.invoke(job); err != nil {
logger.Errorf(ctx, "failed to invoke")
}
}()
return &pb.Empty{}, nil
}
func Invoke(ctx context.Context, job *api.Job) (*pb.Empty, error{
ma.workerChannel <- &worker.Work{
Task: job,
WorkerFunction: ma.invoke,
}
return &protobuf.Empty{}, nil
}
func (worker *Worker) Start(){
go func(){
for {
select{
case job :=<- worker.tasks:{
if job != nil{
err := job.WorkerFunction(job.Task)
if err != nil {
logger.Errorf("worker function failed")
}
}
}
case <- worker.stop:
break
}
}
}()
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yinon Eliraz

Yinon Eliraz

More from Medium

A TL;DR guide to MVC frameworks

Storing and Retrieving Unstructured DynamoDB objects in C# with the AWS SDK

Which is better for web development: node.js or golang?

Get Started with gRPC — CNCF Roadmap