SlackSandbox.Inbox (slack_sandbox v0.1.0)

Copy Markdown View Source

In-memory GenServer that captures messages pushed by SlackSandbox and broadcasts them over PubSub so a live view (or anything else) can render them as they arrive.

Add it to your supervision tree:

children = [
  {SlackSandbox.Inbox, pubsub: MyApp.PubSub}
]

:pubsub is required — it must be a PubSub name already running in your supervision tree (the same one you pass to Phoenix.PubSub.subscribe/2 elsewhere in your app). :max_messages (default 200) caps how many messages the inbox retains; oldest messages are dropped first.

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears the inbox.

Lists captured messages, oldest first.

Returns the PubSub name this inbox was started with, for subscribing.

Pushes a message into the inbox and broadcasts it. Returns :ok.

Starts the inbox. :pubsub is required. Pass name: nil to start it unregistered (useful for running more than one, e.g. in tests).

The PubSub topic messages are broadcast on, as {:message, message}.

Types

message()

@type message() :: map()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(server \\ __MODULE__)

@spec clear(GenServer.server()) :: :ok

Clears the inbox.

list(server \\ __MODULE__)

@spec list(GenServer.server()) :: [message()]

Lists captured messages, oldest first.

pubsub(server \\ __MODULE__)

@spec pubsub(GenServer.server()) :: atom()

Returns the PubSub name this inbox was started with, for subscribing.

push(message, server \\ __MODULE__)

@spec push(message(), GenServer.server()) :: :ok

Pushes a message into the inbox and broadcasts it. Returns :ok.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts the inbox. :pubsub is required. Pass name: nil to start it unregistered (useful for running more than one, e.g. in tests).

topic()

@spec topic() :: String.t()

The PubSub topic messages are broadcast on, as {:message, message}.