dawdle v0.5.0 Dawdle View Source
API for the Dawdle messaging system.
Link to this section Summary
Functions
Send a function to be executed.
Send a function to be executed after a delay.
(DEPRECATED) Set a callback to be called the eafter delay
ms
Returns the total number of subscribers.
Returns the number of subscribers to a specific event.
Registers all known event handlers.
Registers an event handler.
Signals an event.
Starts the pollers if they were not started automatically at application startup.
Stops any running pollers.
Unregisters an event handler.
Link to this section Types
argument()
View Source
argument() :: any()
argument() :: any()
callback() View Source
duration()
View Source
duration() :: non_neg_integer()
duration() :: non_neg_integer()
event()
View Source
event() :: struct()
event() :: struct()
handler()
View Source
handler() :: module()
handler() :: module()
Link to this section Functions
call(fun) View Source
Send a function to be executed.
Note that this is an experimental API.
The function is encoded and enqueued and will be executed on a node running the Dawdle listener. Even if the listener is running on the current node, the function may still be executed on another node.
The passed function is evaluated for its side effects and any return value is ignored.
Returns :ok
when the function is successfully enqueued. Otherwise, returns
an error tuple.
Examples
iex> Dawdle.call(fn ->
...> # Do something expensive...
...> :ok
...> end)
:ok
call_after(delay, fun) View Source
Send a function to be executed after a delay.
Note that this is an experimental API.
The function is encoded and enqueued and will be executed on a node running the Dawdle listener after the specified delay. Even if the listener is running on the current node, the function may still be executed on another node.
The passed function is evaluated for its side effects and any return value is ignored.
Returns :ok
when the function is successfully enqueued. Otherwise, returns
an error tuple.
Examples
iex> Dawdle.call_after(5, fn ->
...> # Do something later...
...> :ok
...> end)
:ok
call_after(callback, argument, delay) View Source
(DEPRECATED) Set a callback to be called the eafter delay
ms
Examples
iex> Dawdle.call_after(fn _arg ->
...> # Do something later...
...> :ok
...> end, 1, 5)
:ok
handler_count()
View Source
handler_count() :: non_neg_integer()
handler_count() :: non_neg_integer()
Returns the total number of subscribers.
handler_count(event)
View Source
handler_count(event()) :: non_neg_integer()
handler_count(event()) :: non_neg_integer()
Returns the number of subscribers to a specific event.
register_all_handlers()
View Source
register_all_handlers() :: :ok
register_all_handlers() :: :ok
Registers all known event handlers.
Dawdle searches through all loaded modules for any that implement the
Dawdle.Handler
behaviour and registers them. This is automatically called
when the :dawdle
application starts.
register_handler(handler, opts \\ []) View Source
Registers an event handler.
After calling this function, the next time the specified event occurs, then the handler function will be called with data from that event.
signal(event, opts \\ []) View Source
Signals an event.
The event is encoded and enqueued and will be processed by a handler running
on a node running the Dawdle listener. See Dawdle.Handler
for information
on creating event handlers.
Use the :delay
option to delay the signaling of the event.
Returns :ok
when the event is successfully enqueued. Otherwise, returns
an error tuple.
Examples
defmodule MyApp.TestEvent do
defstruct :foo, :bar
end
Dawdle.signal(%MyApp.TestEvent{foo: 1, bar: 2})
Dawdle.signal(%MyApp.TestEvent{foo: 1, bar: 2}, delay: 5)
start_pollers()
View Source
start_pollers() :: :ok
start_pollers() :: :ok
Starts the pollers if they were not started automatically at application startup.
stop_pollers()
View Source
stop_pollers() :: :ok
stop_pollers() :: :ok
Stops any running pollers.
unregister_handler(handler)
View Source
unregister_handler(handler()) :: :ok
unregister_handler(handler()) :: :ok
Unregisters an event handler.