O'Reilly logo

Programming Elixir 1.2 by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required