From the course: Advanced Go Programming: Data Structures, Code Architecture, and Testing

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Concurrent processing

Concurrent processing

- [Instructor] Concurrency is a way for us to make the most of our computing resources and aggregate multiple data subsets or windows as we called them in the previous video. Let's have a closer look at how this can be implemented in Go using goroutines and channels. You can easily leverage concurrency in our data processing by using goroutines and channels. As we slice and subset our data, we might want to speed up processing by taking advantage of concurrency. This is one of Go's great strengths. In this example, we create a number slice, loop over each number and start a new goroutine to process it. Once processing is completed, the goroutines send their computed value to the results channel. After the for loop, once all the goroutines are started, the main function receives all the computed values from the results channel and prints them. Due to their nature, channels will maintain the order of the results. While…

Contents