Your Turn

  • Exercise: OTP-Servers-1

    You’re going to start creating a server that implements a stack. The call that initializes your stack will pass in a list of the initial stack contents.

    For now, implement only the pop interface. It’s acceptable for your server to crash if someone tries to pop from an empty stack.

    For example, if initialized with [5,"cat",9], successive calls to pop will return 5, "cat", and 9.

One-Way Calls

The call function calls a server and waits for a reply. But sometimes you won’t want to wait because there is no reply coming back. In those circumstances, use the GenServer cast function. (Think of it as casting your request into the sea of servers.)

Just like call is passed to handle_call in the server, cast is sent to ...

Get Programming Elixir 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.