A small golang library that runs a set of functions safely (without panics) and returns simple stats.
import "github.com/spider-pigs/funcrunner"
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)
}