O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

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

Sending and Receiving Events

Everything we’ve done so far is setting us up to do one thing: process events. Just as controllers receive requests, channels receive events. With channels, we receive a message containing an event name, such as new_message, and a payload of arbitrary data.

Each channel module has three ways to receive events. You’ll learn more about these callback functions in detail soon. For now, know that handle_in receives direct channel events, handle_out intercepts broadcast events, and handle_info receives OTP messages.

Taking Our Channels for a Trial Run

To test-drive everything we’ve put together so far, let’s make our join function send our channel a :ping message every five seconds, like this:

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