# `AshBackendDrivenOptimisticUi.PushCollector`
[🔗](https://github.com/Undeadlol1/ash_backend_driven_optimistic_ui/blob/v0.1.0/lib/ash_backend_driven_optimistic_ui/push_collector.ex#L1)

A per-process list of the pushes sent while handling one request.

`open/0` starts collecting in the calling process, every push sender calls
`record/2`, and `drain/0` returns the pushes in send order and stops
collecting. A push recorded in a process started for the request, such as
the task Ash runs an action in under a deadline, reaches the collector of
the nearest `$callers` ancestor that has one open. Pushes from any other
process, or after the collector was drained, are dropped.

`drain_reconciliation/1` is what any transport sends back with the answer:
call `open/0` before the action runs, then put its result where the client
reads it.

# `drain`

```elixir
@spec drain() :: [map()]
```

# `drain_reconciliation`

```elixir
@spec drain_reconciliation([String.t()]) :: map() | nil
```

Stops collecting and returns `%{"pushes" => pushes, "retracted" => ids}`, or
`nil` when nothing was pushed and no optimistic id was sent. `header_values`
are the values of the `x-optimistic-ids` request header, each a
comma-separated list. An id is retracted when no push carries it as its
`id` or `sync_cursor`.

# `open`

```elixir
@spec open() :: :ok
```

# `optimistic_ids_header`

```elixir
@spec optimistic_ids_header() :: String.t()
```

The request header, or metadata key, carrying the ids the client showed at once.

# `record`

```elixir
@spec record(String.t(), map()) :: :ok
```

---

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