Skip to Main Content
Programming Phoenix
book

Programming Phoenix

by Chris McCord, Bruce Tate, Jose Valim
April 2016
Beginner to intermediate content levelBeginner to intermediate
300 pages
6h 58m
English
Pragmatic Bookshelf
Content preview from Programming Phoenix

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:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Elm

Programming Elm

Jeremy Fairbank
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781680501926Errata Page