Module ebus

Main ebus` interface. This module also works as a wrapper on top of `ebus_ps module.

Behaviours: application.

See also: ebus_ps.

Description

Main ebus` interface. This module also works as a wrapper on top of `ebus_ps module.

Data Types

dispatch_fun()

dispatch_fun() = fun(([term()]) -> term())

Receives as argument the subscribers list. Then it should choose one subscriber from the given list and return it.

dispatch_opt()

dispatch_opt() = {scope, local | global} | {dispatch_fun, dispatch_fun()}

Available dispatch options.

dispatch_opts()

dispatch_opts() = [dispatch_opt()]

Dispatch options.

handler()

handler() = pid()

options()

options() = ebus_ps_local:options()

sub/4 options.

topic()

topic() = iodata()

Function Index

default_ps_server/0Returns default ebus server name: ebus_ps.
dispatch/2Equivalent to dispatch(Topic, Message, []).
dispatch/3Equivalent to dispatch(server(), Topic, Message, Opts).
dispatch/4 Sends a message only to one subscriber handler of the Topic.
local_subscribers/1Equivalent to local_subscribers(server(), Topic).
local_subscribers/2 Same as subscribers/2 but only local subscribers handlers for the given Topic are returned.
local_topics/0Equivalent to local_topics(server()).
local_topics/1 Same as topics/1 but only local topics are returned.
pub/2Equivalent to pub(server(), Topic, Message).
pub/3 Sends a message to all subscribers of a topic.
pub_from/3Equivalent to pub_from(server(), From, Topic, Message).
pub_from/4 Same as pub/3 but message is not sent to FromHandler.
server/0Returns the registered ebus server name.
start/0Starts ebus application.
stop/0Stops ebus application.
sub/2Equivalent to sub(server(), Handler, Topic).
sub/3Equivalent to sub(Server, Handler, Topic, []).
sub/4 Subscribes the Handler given Topic.
subscribers/1Equivalent to subscribers(server(), Topic).
subscribers/2 Returns a set of all subscribers handlers (local and global) for the given Topic.
topics/0Equivalent to topics(server()).
topics/1 Returns the list of all topics (local and global) in use.
unsub/2Equivalent to unsub(server(), Handler, Topic).
unsub/3 Unsubscribes the given Handler from the Topic.

Function Details

default_ps_server/0

default_ps_server() -> ebus_ps

Returns default ebus server name: ebus_ps.

dispatch/2

dispatch(Topic, Message) -> any()

Equivalent to dispatch(Topic, Message, []).

dispatch/3

dispatch(Topic, Message, Opts) -> any()

Equivalent to dispatch(server(), Topic, Message, Opts).

dispatch/4

dispatch(Server::atom(), Topic::topic(), Message::term(), Opts::dispatch_opts()) -> ok

Sends a message only to one subscriber handler of the Topic.

Options:

Examples:

  > ebus:dispatch("bar", #{topic => "foo", payload => "hi"}).
  ok
  > ebus:dispatch("bar", #{topic => "foo", payload => "hi"}, []).
  ok
  > ebus:dispatch(ebus_ps, "bar", "my message",
      [{scope, global}, {dispatch_fun, fun([H | _]) -> H end}]).
  ok

local_subscribers/1

local_subscribers(Topic) -> any()

Equivalent to local_subscribers(server(), Topic).

local_subscribers/2

local_subscribers(Server::atom(), Topic::topic()) -> [pid()]

Same as subscribers/2 but only local subscribers handlers for the given Topic are returned.

Example:

  > ebus:local_subscribers(ebus_ps, <<"foo">>).
  [<0.48.0>, <0.49.0>]

local_topics/0

local_topics() -> any()

Equivalent to local_topics(server()).

local_topics/1

local_topics(Server::atom()) -> [binary()]

Same as topics/1 but only local topics are returned.

Example:

  > ebus:local_topics().
  [<<"foo">>, <<"bar">>]
  > ebus:local_topics(ebus_ps).
  [<<"foo">>, <<"bar">>]

pub/2

pub(Topic, Message) -> any()

Equivalent to pub(server(), Topic, Message).

pub/3

pub(Server::atom(), Topic::topic(), Message::term()) -> ok | {error, term()}

Sends a message to all subscribers of a topic.

Examples:

  > ebus:pub("bar", #{topic => "foo", payload => "hi"}).
  ok
  > ebus:pub(ebus_ps, "bar", #{topic => "foo", payload => "hi"}).
  ok

pub_from/3

pub_from(From, Topic, Message) -> any()

Equivalent to pub_from(server(), From, Topic, Message).

pub_from/4

pub_from(Server::atom(), FromHandler::handler(), Topic::topic(), Message::term()) -> ok | {error, term()}

Same as pub/3 but message is not sent to FromHandler.

Examples:

  > ebus:pub_from(self(), "foo", <<"message">>).
  ok
  > ebus:pub_from(ebus_ps, self(), "foo", <<"message">>).
  ok

server/0

server() -> atom()

Returns the registered ebus server name.

start/0

start() -> {ok, term()} | {error, term()}

Starts ebus application.

stop/0

stop() -> ok | {error, term()}

Stops ebus application.

sub/2

sub(Handler, Topic) -> any()

Equivalent to sub(server(), Handler, Topic).

sub/3

sub(Server, Handler, Topic) -> any()

Equivalent to sub(Server, Handler, Topic, []).

sub/4

sub(Server::atom(), Handler::handler(), Topic::topic(), Opts::options()) -> ok | {error, term()}

Subscribes the Handler given Topic.

Options:

Examples:

  > ebus:sub(self(), <<"foo">>).
  ok
  > ebus:sub(ebus_ps, self(), <<"foo">>).
  ok
  > ebus:sub(ebus_ps, self(), <<"foo">>, []).
  ok
  > ebus:sub(ebus_ps, self(), <<"foo">>,
      [{fastlane, {FastPid, my_serializer, [<<"event1">>]}]).
  ok

subscribers/1

subscribers(Topic) -> any()

Equivalent to subscribers(server(), Topic).

subscribers/2

subscribers(Server::atom(), Topic::topic()) -> [pid()]

Returns a set of all subscribers handlers (local and global) for the given Topic.

Example:

  > ebus:subscribers(ebus_ps, <<"foo">>).
  [<0.48.0>, <0.49.0>]

topics/0

topics() -> any()

Equivalent to topics(server()).

topics/1

topics(Server::atom()) -> [binary()]

Returns the list of all topics (local and global) in use. This is an expensive and private operation.

This is an expensive operation. DO NOT USE IT IN PROD

Example:

  > ebus:topics().
  [<<"foo">>, <<"bar">>]
  > ebus:topics(ebus_ps).
  [<<"foo">>, <<"bar">>]

unsub/2

unsub(Handler, Topic) -> any()

Equivalent to unsub(server(), Handler, Topic).

unsub/3

unsub(Server::atom(), Handler::handler(), Topic::topic()) -> ok | {error, term()}

Unsubscribes the given Handler from the Topic.

Example:

  > ebus:unsub(self(), <<"foo">>).
  ok
  > ebus:unsub(ebus_ps, self(), <<"foo">>).
  ok


Generated by EDoc