OpenUI.Stream (OpenUI v0.1.1)

Copy Markdown View Source

Parses a response a chunk at a time (language.md, section 4).

After every chunk, program/1 gives a program that renders: completed statements are read once and kept, and the cut-off tail is closed implicitly and read again on each chunk. A cut-off statement never replaces a completed one with the same name. When the host ends the stream with finish/1, the program equals a batch parse of the whole text.

stream =
  MyApp.Library
  |> OpenUI.Stream.new()
  |> OpenUI.Stream.push("root = Stack([title])\ntitle = Te")

OpenUI.Stream.program(stream)

Summary

Functions

Ends the stream: the cut-off tail completes, as in a batch parse of the whole text.

True once finish/1 ran.

Starts a stream for a library.

The program as of the latest chunk.

Adds the next chunk. A chunk after finish/1 starts a new stream.

The text received so far, including the bytes held back from a character the last chunk cut, so a caller can take the next chunk as what comes after it.

Types

t()

@type t() :: %OpenUI.Stream{
  buffer: String.t(),
  completed: [OpenUI.Statement.t()],
  completed_prefix: String.t(),
  final: OpenUI.Program.t() | nil,
  held: binary(),
  library: OpenUI.Library.t()
}

Functions

finish(stream)

@spec finish(t()) :: t()

Ends the stream: the cut-off tail completes, as in a batch parse of the whole text.

finished?(stream)

@spec finished?(t()) :: boolean()

True once finish/1 ran.

new(library)

@spec new(OpenUI.Library.t() | module()) :: t()

Starts a stream for a library.

program(stream)

@spec program(t()) :: OpenUI.Program.t()

The program as of the latest chunk.

push(stream, chunk)

@spec push(t(), String.t()) :: t()

Adds the next chunk. A chunk after finish/1 starts a new stream.

text(stream)

@spec text(t()) :: binary()

The text received so far, including the bytes held back from a character the last chunk cut, so a caller can take the next chunk as what comes after it.