AshBackendDrivenOptimisticUi.PushCollector (AshBackendDrivenOptimisticUi v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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.

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

Functions

drain()

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

drain_reconciliation(header_values)

@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()

@spec open() :: :ok

optimistic_ids_header()

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

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

record(event, payload)

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