From the course: Applied Concurrency in Go

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Using channels in the Orders app

Using channels in the Orders app - Go Tutorial

From the course: Applied Concurrency in Go

Using channels in the Orders app

- [Instructor] Now that we understand the basic usage of channels and the select keyword, let's have a look at how we can use them on the Orders App. As we remember from previous sections, the server package exposes a rest API, which the user interacts with. The handlers then map the HTTP requests to our internal models. The repo and the database packages manage and create the order models. In our previous solution, we added a lock to the repo service. This allowed the process orders method to only be invoked by one order at a time. However, using locks and application code does have its drawbacks. First, the code becomes more verbose and error prone. Developers need to remember to lock and unlock the lock for the correct behavior. Secondly, looking at the code, it's not intuitive to understand what the lock is used for. Even with good naming, it might be difficult to reason about using it. Finally, as the lock…

Contents