# `WardrikWeb.Follow`

Keeps a LiveView up to date with a streamed operation.

When events arrive, it reloads the view. It reloads at most once every 250 ms.

    def mount(_params, _session, socket),
      do: {:ok, socket |> load() |> WardrikWeb.Follow.start("events.list", %{})}

    def handle_info({WardrikWeb.Follow, _message} = message, socket),
      do: {:noreply, WardrikWeb.Follow.handle(message, socket, &load/1)}

  * The stream starts only once the LiveView is connected.
  * The stream runs in a task linked to the LiveView. When one exits, the other exits too.
  * `@live` is `true` while the stream is open. When the stream fails or ends, `@live` is
    `false` and `@stopped` gives the reason.

# `agents`

```elixir
@spec agents(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()
```

Streams events for every agent the scope can see, using `events.list`.

Agents created later are included the next time the view mounts.

# `handle`

```elixir
@spec handle(
  {module(), term()},
  Phoenix.LiveView.Socket.t(),
  (term() -&gt; term()),
  keyword()
) ::
  Phoenix.LiveView.Socket.t()
```

Handles a message sent by the stream.

It calls `reload` with the socket after events arrive. If you pass `:on_event`, it calls it
with each event.

# `start`

```elixir
@spec start(Phoenix.LiveView.Socket.t(), String.t(), map()) ::
  Phoenix.LiveView.Socket.t()
```

Starts streaming operation `id` with `input`, in the socket's scope.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
