From 8d517eb7adfa8e45f32879bc0a8c87b5738b53e2 Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Thu, 22 Jun 2023 16:11:53 -0400 Subject: [PATCH] Do: Remove concurrency limit --- README.md | 2 +- do.go | 9 ++++----- example_test.go | 27 ++++++++++++++------------- panic_test.go | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a2b82d4..1e5706d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ To execute heterogenous tasks with a set number of workers, just use `workgroup. ```go -err := workgroup.Do(3, +err := workgroup.Do( func() error { return doThingA(), }, diff --git a/do.go b/do.go index 96383f2..f1a535b 100644 --- a/do.go +++ b/do.go @@ -1,13 +1,12 @@ package workgroup -// Do starts n concurrent workers (or GOMAXPROCS workers if n < 1) -// that execute each function. +// Do starts each function in its own goroutine. // Errors returned by a function do not halt execution, // but are joined into a multierror return value. // If a function panics during execution, -// the panic will be caught and rethrown in the parent Goroutine. -func Do(n int, fns ...func() error) error { - return DoEach(n, fns, func(in func() error) error { +// a panic will be caught and rethrown in the parent Goroutine. +func Do(fns ...func() error) error { + return DoEach(len(fns), fns, func(in func() error) error { return in() }) } diff --git a/example_test.go b/example_test.go index 7b5269a..447a170 100644 --- a/example_test.go +++ b/example_test.go @@ -126,19 +126,20 @@ func ExampleDoEach() { func ExampleDo() { start := time.Now() - err := workgroup.Do(3, func() error { - time.Sleep(50 * time.Millisecond) - fmt.Println("hello") - return nil - }, func() error { - time.Sleep(100 * time.Millisecond) - fmt.Println("world") - return nil - }, func() error { - time.Sleep(200 * time.Millisecond) - fmt.Println("from workgroup.Do") - return nil - }) + err := workgroup.Do( + func() error { + time.Sleep(50 * time.Millisecond) + fmt.Println("hello") + return nil + }, func() error { + time.Sleep(100 * time.Millisecond) + fmt.Println("world") + return nil + }, func() error { + time.Sleep(200 * time.Millisecond) + fmt.Println("from workgroup.Do") + return nil + }) if err != nil { fmt.Println("error", err) } diff --git a/panic_test.go b/panic_test.go index 51b97df..0746e4e 100644 --- a/panic_test.go +++ b/panic_test.go @@ -77,7 +77,7 @@ func TestDo_panic(t *testing.T) { err error ) r := try(func() { - err = workgroup.Do(1, + err = workgroup.Do( func() error { n.Add(1) return nil