Making Our Server into a Component

Earlier I said that what Elixir calls an application, most people would call a component or a service. That’s certainly what our sequence server is: a freestanding chunk of code that enjoyed generating successive numbers.

Despite being the canonical way of writing this, I don’t like my implementation. It puts three things into a single source file:

  • The API
  • The logic of our service (adding one)
  • The implementation of that logic in a server

Have another look at the code here. If you didn’t know what it did, how would you find out? Where’s the code that does the component’s logic? (The image gives you a hint.) It isn’t obvious, and this is just a trivial service. Imagine working with a really complex one, with lots ...

Get Programming Elixir ≥ 1.6 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.