From the course: Go Recipes: Practical Projects
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Converting sequential code to concurrent in Go - Go Tutorial
From the course: Go Recipes: Practical Projects
Converting sequential code to concurrent in Go
- [Instructor] One of goals, main strength, is it's support for concurrency. Before you start writing concurrent code start with writing sequential code. Sequential code is much simpler and easier to understand and maintain. Move to concurrent code only if you have a need for the extra performance. So you have a web server that returns a CSV per day with some information about texts writes. The CSV will look something like this. We have the start of the write, the end of the write, the distance, and the number of passengers. Let's start with the sequential code. So here's the sequential code. We want to calculate the distance for a whole month. So we need to call the API per day. So we start with the total distance of zero and the date is the month. And while we are still in the same month, we are going to construct a URL for that day, do a get request to get the data, do some error checking and then calculates the distance for the day, edit to the total distance and advance the day…