Skip to content

falmar/krun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Krun - QueueRun

Build Krun

Krun is a simple worker queue, which provides an easy way to manage and execute jobs concurrently. It can wait for all jobs to finish, and get the results from the executed jobs. The package can be found at github.com/falmar/krun.

Installation

To install the Krun package, simply run:

go get -u github.com/falmar/krun

Usage

Here's a basic example of how to use the Krun package:

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/falmar/krun"
)

func main() {
	queue := krun.New(&krun.Config{
		Size:      5, // number of workers
		WaitSleep: time.Microsecond,
	})

	job := func(ctx context.Context) (interface{}, error) {
		time.Sleep(time.Millisecond * 100)
		return "Hello, Krun!", nil
	}

	ctx := context.Background()
	resChan := queue.Run(ctx, job)

	res := <-resChan
	if res.Error != nil {
		fmt.Println("Error:", res.Error)
		os.Exit(1)
	}

	queue.Wait(ctx)

	fmt.Println("Result:", res.Data.(string))
}

License

Krun is released under the MIT License. See LICENSE for more information.

TODO:

  • unit test
  • go releaser

About

A simple queue/worker pool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages