Skip to content

Commit

Permalink
ForEach
Browse files Browse the repository at this point in the history
  • Loading branch information
destel committed Apr 11, 2024
1 parent 05225c2 commit ab19d70
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package rill_test

import (
"fmt"
"math/rand"
"time"

"github.com/destel/rill"
)

func Example_forEach() {
items := rill.FromSlice([]string{"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10"}, nil)

err := rill.ForEach(items, 3, func(item string) error {
randomSleep(1 * time.Second) // emulate long processing
fmt.Println(item)
return nil
})
if err != nil {
fmt.Println(err)
}
}

func randomSleep(max time.Duration) {
time.Sleep(time.Duration(rand.Intn(int(max))))
}

0 comments on commit ab19d70

Please sign in to comment.