Skip to content

Handling of individual task errors during concurrent execution #48

Closed Answered by destel
1ch0 asked this question in Q&A
Discussion options

You must be logged in to vote

There are 3 ways to achieve this. Suppose you have a pipeline that returns a results channel in the end.

Go's for-range loop

results is a regular Go channel and can be processed with for-range. Just make sure you add a deferred DrainNB call, to prevent leaks in case of early return

defer rill.DrainNB(results)

for result := range results {
	if result.Error != nil {
		fmt.Println("Error:", result.Error)
	} else {
		fmt.Println("Value:", result.Value)
	}
}

using rill.Catch

resultsWoErrors := rill.Catch(results, 1, func(err error) error {
	fmt.Println("Error:", err)
	return nil // Do not pass this error to the next stage
})

_ = rill.ForEach(resultsWoErrors, 1, func(result int) error {
	fmt.P…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 1ch0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants