Topical (topical v0.1.3)

This module provides the high level interface for interacting with topics. Primarily for subscribing (and unsubscribing), but also for sending requests.

After subscribing, a client will initially receive a {:reset, ref, value} message, and then subsequent {:updates, ref, updates} messages when the value of the topic changes, where updates is a list with each item being one of:

  • {:set, path, value}: the value has been set at the path.
  • {:unset, path, key}: the key has been unset from the object at the path.
  • {:insert, path, index, values}: the values have been inserted into the array at the path.
  • {:delete, path, index, count}: count values have been deleted from the array at the path, from the position index.

A client can interact directly with a topic by executing actions (which returns a result), or by notifying (without waiting for a result). These are analogous to GenServer.call/3 and GenServer.cast/2. Be aware that a topic is blocked while processing a request.

Link to this section Summary

Functions

Returns a specification to start a Topical registry under a supervisor.

Subscribes to the specified topic (in the specified registry).

Unsubscribes from a topic (in the specified registry).

Link to this section Functions

Link to this function

child_spec(options)

Returns a specification to start a Topical registry under a supervisor.

Link to this function

execute(registry, topic, action, args \\ {}, context \\ nil)

Executes an action in a topic.

example

Example

Topical.execute(MyApp.Topical, "lists/foo", "add_item", {"Test", false})
#=> {:ok, "item123"}
Link to this function

notify(registry, topic, action, args \\ {}, context \\ nil)

Send a notification to a registry.

This is similar to execute/4, except no result is waited for.

example

Example

Topical.notify(MyApp.Topical, "lists/foo", "update_done", {"item123", true})
#=> :ok
Link to this function

subscribe(registry, topic, pid, context \\ nil)

Subscribes to the specified topic (in the specified registry).

Returns {:ok, ref}, where the ref is a reference to the subscription.

The pid will be send messages, as described above.

example

Example

Topical.subscribe(MyApp.Topical, "lists/foo", self())
#=> {:ok, #Reference<0.4021726225.4145020932.239110>}
Link to this function

unsubscribe(registry, topic, ref)

Unsubscribes from a topic (in the specified registry).

example

Example

Topical.unsubscribe(MyApp.Topical, "lists/foo", ref)