Filo.Streams (Filo v0.2.0)

Copy Markdown View Source

Registry of live Filo.Stream processes — the find-or-start layer between the HTTP plug and the per-stream processes.

A Filo.Streams supervisor owns a Registry (mapping stream_id to the stream process) and a DynamicSupervisor (the streams themselves). The plug:

  • calls create/2 when a request arrives with no baton, getting back a fresh stream_id and initial seq to mint the first baton;
  • calls lookup/2 with the stream_id decoded from a baton to find the stream for the next request.

Stream ids and initial sequence numbers are drawn from :crypto.strong_rand_bytes/1, so they are unguessable across the full 64-bit range, matching libsql.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a new stream and registers it under a fresh, random stream_id.

Finds the stream process for stream_id, or :error if there is none.

Starts the streams supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

create(name, stream_opts)

@spec create(
  Supervisor.supervisor(),
  keyword()
) :: {:ok, non_neg_integer(), non_neg_integer(), pid()} | {:error, term()}

Starts a new stream and registers it under a fresh, random stream_id.

stream_opts are forwarded to Filo.Stream.start_link/1 (:executor, :open_arg, :idle_timeout); the :seq and registry :name are supplied here. Returns {:ok, stream_id, seq, pid}, or {:error, reason} if the executor cannot open a connection.

lookup(name, stream_id)

@spec lookup(Supervisor.supervisor(), non_neg_integer()) :: {:ok, pid()} | :error

Finds the stream process for stream_id, or :error if there is none.

start_link(opts)

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

Starts the streams supervisor.

Required option :name is the supervisor's registered name; the Registry and DynamicSupervisor are registered under names derived from it.