O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The golang.org/x/sync/errgroup package helps to simplify the error propagation and cancellation by context for goroutine groups. The Group contains the Go method which consumes the no-arg function returning the error. This function should contain the task which should be done by the executed goroutine. The Wait method of the Group from errgroup waits until all executed tasks from the Go method are complete, and if any of them are returned err, then the first non-nil error is returned. This way, it is possible to simply propagate the error from the group of running goroutines.

Note that the Group is also created with the use of context. The Context serves as the mechanism to cancel other tasks, if the error occurs. After the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required