Skip to content

Latest commit

 

History

History
73 lines (57 loc) · 1.56 KB

README.md

File metadata and controls

73 lines (57 loc) · 1.56 KB

goest-worker

Package goest-worker implements a priority queue of tasks and a pool of goroutines for launching and managing the states of these tasks.

Features

  • Lightweight queue of jobs with concurrent processing
  • Periodic tasks (use cron expressions or time.Duration for repeating)
  • Ability to add tasks with priority to the queue

Installation

To install goest-worker, use

go get github.com/yobayob/goest-worker

Getting started

package main

import (
	worker "github.com/yobayob/goest-worker"
	"runtime"
	"fmt"
	"context"
)
/*
Simple task with parameters and results
You can getting results by method `Results()` task.Run().Wait().Results()
 */
func sum(a, b int) (int) {
	res := a+b
	fmt.Printf("%d + %d = %d\n", a, b, res)
	return res
}

func div(a, b int) (int) {
	res := a / b
	fmt.Printf("%d / %d\n", a, b)
	return res
}


func main()  {
	pool := worker.New().Start(context.TODO(), runtime.NumCPU())  	// create workers pool
	sumJob := pool.NewJob(sum)
	var result int
	err := sumJob.Run(1111, 2156).Wait().Results(&result)
	if err != nil {
		panic(err)
	}
	fmt.Println("result is", result)
	divJob := pool.NewJob(div)
	err = divJob.Run( 144, 12).Wait().Results(&result)
	if err != nil {
		panic(err)
	}
	fmt.Println("result is", result)
	pool.Stop()
}

Examples

see examples - https://github.com/yobayob/goest-worker/tree/master/examples

Documentation

godoc - https://godoc.org/github.com/fruitfrills/goest-worker