-
Does the library currently provide a mechanism to continue execution of concurrent tasks even if some tasks encounter errors? I'm interested in a feature that allows all tasks to complete and then returns a summary of successes and failures. If this functionality exists, please point me to the relevant documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There are 3 ways to achieve this. Suppose you have a pipeline that returns a Go's for-range loop
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.CatchresultsWoErrors := 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.Println("Value:", result)
return nil
}) Go 1.23 iterators and rill.ToSeq2This is similar to the first approach, but does not require the for value, err := range rill.ToSeq2(results) {
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Value:", value)
}
} |
Beta Was this translation helpful? Give feedback.
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 deferredDrainNB
call, to prevent leaks in case of early returnusing rill.Catch