Skip to content

Commit

Permalink
Remove ~func type params in parallel package (#23)
Browse files Browse the repository at this point in the history
* Remove some ~func type params.

* Upgrade dependency.

* go mod tidy
  • Loading branch information
bobg authored Aug 17, 2024
1 parent 1998b09 commit 50a3d39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.23

require golang.org/x/sync v0.8.0

require github.com/bobg/seqs v1.0.0
require github.com/bobg/seqs v1.2.0

require github.com/bobg/go-generics/v3 v3.7.0 // indirect

retract v4.0.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/bobg/go-generics/v3 v3.7.0 h1:4SJHDWqONTRcA8al6491VW/ys6061bPCcTcI7YnIHPc=
github.com/bobg/go-generics/v3 v3.7.0/go.mod h1:wGlMLQER92clsh3cJoQjbUtUEJ03FoxnGhZjaWhf4fM=
github.com/bobg/seqs v1.0.0 h1:BcBwTAMX9DKkKPx6Q7+uiZwuMw2/Pj3c2HZA9nJBPag=
github.com/bobg/seqs v1.0.0/go.mod h1:icgB+vXIoU6s675tLYVAgcUYry1PkYwgEKvzOuFemOk=
github.com/bobg/seqs v1.2.0 h1:y9SS1zisfkNQepd+xia/3ELDYR4T4vuLTyCA4UVOiKA=
github.com/bobg/seqs v1.2.0/go.mod h1:icgB+vXIoU6s675tLYVAgcUYry1PkYwgEKvzOuFemOk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
Expand Down
8 changes: 4 additions & 4 deletions parallel/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (e Error) Unwrap() error {
//
// The resulting slice has length n.
// The value at position i comes from worker i.
func Values[T any, F ~func(context.Context, int) (T, error)](ctx context.Context, n int, f F) ([]T, error) {
func Values[T any](ctx context.Context, n int, f func(context.Context, int) (T, error)) ([]T, error) {
g, ctx := errgroup.WithContext(ctx)
result := make([]T, n)

Expand Down Expand Up @@ -74,7 +74,7 @@ func Values[T any, F ~func(context.Context, int) (T, error)](ctx context.Context
// but not before the iterator has been fully consumed.
// The error (if there is one) is of type [Error],
// whose N field indicates which worker failed.
func Producers[T any, F ~func(context.Context, int, func(T) error) error](ctx context.Context, n int, f F) (iter.Seq[T], *error) {
func Producers[T any](ctx context.Context, n int, f func(context.Context, int, func(T) error) error) (iter.Seq[T], *error) {
ch := make(chan T)
g, innerCtx := errgroup.WithContext(ctx)

Expand Down Expand Up @@ -126,7 +126,7 @@ func Producers[T any, F ~func(context.Context, int, func(T) error) error](ctx co
// After any error, the value-sending callback will return an error.
// (Not the original error, however.
// For that, the caller should still invoke the close callback.)
func Consumers[T any, F ~func(context.Context, int, T) error](ctx context.Context, n int, f F) (func(T) error, func() error) {
func Consumers[T any](ctx context.Context, n int, f func(context.Context, int, T) error) (func(T) error, func() error) {
ch := make(chan T, n)

g, ctx := errgroup.WithContext(ctx)
Expand Down Expand Up @@ -175,7 +175,7 @@ func Consumers[T any, F ~func(context.Context, int, T) error](ctx context.Contex
//
// Each call of the callback is synchronous.
// Any desired concurrency is the responsibility of the caller.
func Pool[T, U any, F ~func(T) (U, error)](n int, f F) func(T) (U, error) {
func Pool[T, U any](n int, f func(T) (U, error)) func(T) (U, error) {
var (
running int
mu sync.Mutex
Expand Down

0 comments on commit 50a3d39

Please sign in to comment.