Chapter 4. Writing server applications with GenServer

 

This chapter covers

  • OTP and why you should use it
  • OTP behaviors
  • Rewriting Metex to use the GenServer OTP behavior
  • Structuring your code to use GenServer
  • Handling synchronous and asynchronous requests using callbacks
  • Managing server state
  • Cleanly stopping the server
  • Registering the GenServer with a name

In this chapter, you begin by learning about OTP. OTP originally stood for Open Telecom Platform and was coined by the marketing geniuses over at Ericsson (I hope they don’t read this!). It’s now only referred to by its acronym. Part of the reason is that the naming is myopic—the tools provided by OTP are in no way specific to the telecommunications domain. Nonetheless, the name has stuck, for better or worse. (Naming is said to be one of the most difficult problems in computer science.)

In this chapter, you’ll learn exactly what OTP is. Then we’ll look at some of the motivations that drove its creation. You’ll also see how OTP behaviors can help you build applications that reduce boilerplate code, drastically reduce potential concurrency bugs, and take advantage of code that has benefited from decades of hard-earned experience.

4.1. What is OTP?

4.2. OTP behaviors

4.3. Hands-on OTP: revisiting Metex

4.4. Exercise

4.5. Summary

sitemap