This recipe will show how to easily use the errgroup extension package to detect the error within the group of goroutines that run subtasks, within a common task.
Propagating errors with errgroup
How to do it...
- Open the console and create the folder chapter10/recipe07.
- Navigate to the directory.
- Create the file lines.go with the following content:
package main
import (
"bufio"
"context"
"fmt"
"log"
"strings"
"golang.org/x/sync/errgroup"
)
const data = `line one
line two with more words
error: This is erroneous line`
func main() {
log.Printf("Application...