dawdle v0.5.1 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

Link to this section Functions

Link to this function

call(fun) View Source
call((... -> any())) :: :ok | {:error, term()}

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
Link to this function

call_after(delay, fun) View Source
call_after(duration(), (... -> any())) :: :ok | {:error, term()}

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
Link to this function

call_after(callback, argument, delay) View Source
call_after(callback(), argument(), duration()) :: :ok | {:error, term()}

This function is deprecated. Use call_after/2 or signal/2 instead.

(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
Link to this function

handler_count() View Source
handler_count() :: non_neg_integer()

Returns the total number of subscribers.

Link to this function

handler_count(event) View Source
handler_count(event()) :: non_neg_integer()

Returns the number of subscribers to a specific event.

Link to this function

register_all_handlers() View Source
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.

Link to this function

register_handler(handler, opts \\ []) View Source
register_handler(handler(), Keyword.t()) :: :ok | {:error, term()}

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.

Link to this function

signal(event, opts \\ []) View Source
signal(event() | [event()], Keyword.t()) :: :ok | {:error, term()}

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)
Link to this function

start_pollers() View Source
start_pollers() :: :ok

Starts the pollers if they were not started automatically at application startup.

Link to this function

stop_pollers() View Source
stop_pollers() :: :ok

Stops any running pollers.

Link to this function

unregister_handler(handler) View Source
unregister_handler(handler()) :: :ok

Unregisters an event handler.