TermUI.Widgets.StreamWidget.Consumer (TermUI v1.0.0)

View Source

GenStage consumer for StreamWidget.

This module provides a GenStage consumer that forwards events to a process as {:stream_items, events}. GenStage manages subscription demand; this adapter does not dynamically change demand from the widget's buffer occupancy.

With an embedded widget, pass the runtime/root PID and forward received messages from the root's optional handle_info/2 to the stream widget's state callback.

Usage

# Start the consumer linked to a widget process
{:ok, consumer} = StreamWidget.Consumer.start_link(widget_pid)

# Subscribe to a producer
GenStage.sync_subscribe(consumer, to: producer)

# Or subscribe with options
GenStage.sync_subscribe(consumer, to: producer, max_demand: 100, min_demand: 50)

Summary

Functions

Starts a consumer linked to a widget process.

Functions

start_link(widget_pid, opts \\ [])

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

Starts a consumer linked to a widget process.

Options

  • :demand - Retained metadata (default: 10); use max_demand and min_demand in subscribe/3 to control the actual subscription

subscribe(consumer, producer, opts \\ [])

@spec subscribe(GenServer.server(), GenStage.stage(), keyword()) ::
  {:ok, reference()} | {:error, term()}

Subscribe to a producer.