Coder Social home page Coder Social logo

epubnub's Introduction

README

Author: Tristan Sloughter [email protected] website: http://blog.erlware.org

Version: 0.1.0

Quick Start

  • Build
$ ./rebar3 compile
  • Test
$ ./rebar3 shell
1> application:ensure_all_started(epubnub).
ok
2> epubnub:publish(<<"hello_world">>, <<"hello">>).
{[1,<<"Sent">>,<<"13612809348896246">>]}

Examples

src/epn_example_client has a simple example of a gen_server subscribing to a channel. The init function takes an EPN record, created with epubsub:new() in start_link and requests to subscribe to the "hello_world" channel and sends its PID with the self() function so new messages are sent to this process.

init([EPN]) ->
    {ok, PID} = epubnub_sup:subscribe(EPN, <<"hello_world">>, self()),
    {ok, #state{pid=PID}}.

Since currently the subscribe loop sends the message with the bang (!) the gen_server will handle the new message in handle_info. The example simply prints out the contents of the message:

handle_info({message, Message}, State) ->
    io:format("~p~n", [Message]),
    {noreply, State}.

To unscribe we call the module stop function that sends an async stop message to the process. The handle_cast function handles this message and return stop telling the gen_server to go to terminate. In terminate we take the PID of the subscribed process to the epubnub unsubscribe function which sends it a terminate message and it exits.

stop() ->
    gen_server:cast(?SERVER, stop).

handle_cast(stop, State) ->
    {stop, normal, State}.

terminate(_Reason, #state{pid=PID}) ->
    epubnub:unsubscribe(PID),
    ok.

epubnub's People

Contributors

tsloughter avatar jwilberding avatar

Watchers

Guillermo Iguaran avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.