Skip to content

A small golang library that runs a set of functions safely and returns simple stats.

License

Notifications You must be signed in to change notification settings

spider-pigs/funcrunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

funcrunner

Build Status Go Report Card GoDoc

A small golang library that runs a set of functions safely (without panics) and returns simple stats.

Install

import "github.com/spider-pigs/funcrunner"

Usage

package main

import (
	"context"
	"errors"
	"fmt"
	"time"

	"github.com/spider-pigs/funcrunner"
)

func main() {
	// create functions that return an error and takes context as param
	ctx := context.Background()
	f1 := func(ctx context.Context) error {
		return nil
	}
	f2 := func(ctx context.Context) error {
		return errors.New("I can't take it anymore")
	}

	// create the runner
	runner := funcrunner.Runner{}
	runner.FuncDone = func(f funcrunner.Func, duration time.Duration, err error) {
		fmt.Printf("function %s has completed, took %s.\n", f, duration)
	}

	// Start the runner
	duration := runner.RunFunc(ctx, f1, f2)
	fmt.Printf("runner has completed, took %s..\n", duration)
}

About

A small golang library that runs a set of functions safely and returns simple stats.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages