Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ~func type params in parallel package #23

Merged
merged 3 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading