Skip to content

Commit

Permalink
Removed unneeded example
Browse files Browse the repository at this point in the history
  • Loading branch information
destel committed Apr 11, 2024
1 parent d888a29 commit 16ef6ad
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,13 @@ type KV struct {
Value string
}

// This example demonstrates how [ForEach] can be used for concurrent processing of items.
// This example demonstrates how [ForEach] can be used for concurrent processing and error handling.
func Example_forEach() {
startedAt := time.Now()
defer func() { fmt.Println("Elapsed:", time.Since(startedAt)) }()

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(1000 * time.Millisecond) // simulate some work
fmt.Println(item)
return nil
})
if err != nil {
fmt.Println("Error:", err)
}
}

// This example demonstrates a pipeline that causes an error in the middle of processing.
// On the final stage, [ForEach] catches the error, returns it, and stops the pipeline.
func Example_errorHandling() {
startedAt := time.Now()
defer func() { fmt.Println("Elapsed:", time.Since(startedAt)) }()

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

items = rill.Map(items, 3, func(item string) (string, error) {
randomSleep(1000 * time.Millisecond) // simulate some work

Expand All @@ -50,6 +32,7 @@ func Example_errorHandling() {
return strings.ToUpper(item), nil
})

// For each will stop on the first error
err := rill.ForEach(items, 3, func(item string) error {
fmt.Println(item)
return nil
Expand Down

0 comments on commit 16ef6ad

Please sign in to comment.