Skip to content

A minimal package to parallelize work and return error

License

Notifications You must be signed in to change notification settings

rnrch/parallelize

Repository files navigation

parallelize

PkgGoDev Go Report Card Github Actions

A minimal package to parallelize work and return error, with respect to k8s.io/client-go/util/workqueue

Usage

e.g.

    ctx, cancel := context.WithCancel(context.Background())
    errCh := parallelize.NewErrorChannel()
    raw := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    result := make([]int, len(raw))
    parallelize.Until(ctx, len(raw), func(index int) {
        res, err := addTen(ctx, raw[index]) // addTen returns (10 + input number)
        if err != nil {
            errCh.SendErrorWithCancel(err, cancel)
            return
        }
        result[index] = res
    })
    if err := errCh.ReceiveError(); err != nil {
        rlog.Error(err, "Running general case", "func", "addTen", "raw", raw)
    }
    rlog.Info("General case result", "func", "addTen", "raw", raw, "result", result)

see more in examples

About

A minimal package to parallelize work and return error

Resources

License

Stars

Watchers

Forks

Packages

No packages published