Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Output<T>

Non-blocking token stream writer. Output enables incremental, interruptible writing of network protocols and data formats.

Output tokens

Output tokens are modeled as primitive numbers, commonly representing Unicode code points, or raw octets; each Output implementation specifies the semantic type of its tokens.

Output states

An Output writer is always in one of three states: cont_​inue, _full, or done. The cont state indicates that the stream is ready to write a single token; the full state indicates that the stream is unable to write additional tokens at this time, but that the stream may logically resume at some point in the future; and the done state indicates that the stream has terminated, and that bind will return the output result. isCont returns true when in the cont state; isFull returns true when in the full state; and isDone returns true when in the done state.

Output results

An Output writer yields a value of type T, obtained via the bind method, representing some implementation defined result of writing the output. For example, an Output<string> implementation may–but is not required to–yield a string containing all code points written to the output.

Non-blocking behavior

Output writers never block. An Output writer that would otherwise block writing additional output instead enters the full state, signaling the output generator to back off producing the output, but to remain prepared to produce additional output in the future. An Output writer enters the done state when it encounters the final end of its output, signaling to the output generator to stop producing.

Output settings

An output generator may alter the tokens it produces based on its Output writer's settings. Uses include pretty printing and styling generated output. OutputSettings subclasses can provide additional parameters understood by specialized output producers.

Cloning

An Output writer may be cloned to branch the token stream in an implementation specified manner. Not all Output implementations support cloning.

see

OutputSettings

see

Writer

Type parameters

  • T

Hierarchy

Implements

Index

Methods

Abstract bind

  • bind(): T

clone

debug

  • debug(object: unknown): Output<T>
  • Writes the code points of the developer-readable Debug string of the given object. Assumes this is a Unicode Output writer with sufficient capacity.

    throws

    OutputException if this Output exits the cont state before the full debug string has been written.

    Parameters

    • object: unknown

    Returns Output<T>

    this

display

  • display(object: unknown): Output<T>
  • Writes the code points of the human-readable Display string of the given object. Assumes this is a Unicode Output writer with sufficient capacity.

    throws

    OutputException if this Output exits the cont state before the full display string has been written.

    Parameters

    • object: unknown

    Returns Output<T>

    this

flush

Abstract isCont

  • isCont(): boolean

Abstract isDone

  • isDone(): boolean

Abstract isError

  • isError(): boolean
  • Returns true when an immediate write will fail due to an error with the token stream. i.e. this Output is in the error state. When true, trap() will return the output error.

    Returns boolean

Abstract isFull

  • isFull(): boolean
  • Returns true when an immediate write will fail, but writes may succeed at some point in the future. i.e. this Output is in the full state.

    Returns boolean

Abstract isPart

  • isPart(): boolean
  • isPart(isPart: boolean): Output<T>
  • Returns true if this is a partial Output that will enter the full state when it is unable to write additional tokens.

    Returns boolean

  • Returns a partial Output equivalent to this Output, if isPart is true; returns a final Output equivalent to this Output if isPart is false. The caller's reference to this Output should be replaced by the returned Output.

    Parameters

    • isPart: boolean

    Returns Output<T>

push

  • push(...tokens: number[]): void

Abstract settings

trap

  • trap(): Error
  • Returns the output error. Only guaranteed to return an error when in the error state.

    throws

    OutputException if this Output is not in the error state.

    Returns Error

Abstract write

  • write(token: number): Output<T>
  • write(string: string): Output<T>

writeln

  • writeln(string?: undefined | string): Output<T>
  • Writes the code points of the given string, followed by the code points of the settings' [[OutputSettings.lineSeparator line separator]. Assumes this is a Unicode Output writer with sufficient capacity.

    throws

    OutputException if this Output exits the cont state before the full string and line separator has been written.

    Parameters

    • Optional string: undefined | string

    Returns Output<T>

    this

Static done

Static error

Static full