Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Do: Remove concurrency limit
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Jun 22, 2023
1 parent b0c25ad commit 8d517eb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To execute heterogenous tasks with a set number of workers, just use `workgroup.
<td>

```go
err := workgroup.Do(3,
err := workgroup.Do(
func() error {
return doThingA(),
},
Expand Down
9 changes: 4 additions & 5 deletions do.go
Original file line number Diff line number Diff line change
@@ -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()
})
}
27 changes: 14 additions & 13 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion panic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d517eb

Please sign in to comment.