Bash.Pipe (Bash v0.6.0)

Copy Markdown View Source

BEAM-native pipe that buffers data between a writer and reader using blocked GenServer.call/3.

Replaces the OS FIFO-backed pipe with a pure-BEAM implementation that works inside a virtual filesystem sandbox without touching the real filesystem or spawning OS processes.

A single writer appends data; a single reader consumes it line-by-line or all at once. When no data is available the reader parks inside a GenServer.call and is unblocked as soon as the writer delivers data or signals EOF via close_write/1.

stateDiagram-v2
    [*] --> Open : create/1

    Open --> Open : write/2 (buffer += data, fulfill parked reader)
    Open --> Open : read_line/1 (line ready → return immediately)
    Open --> Parked : read_line/1 (no complete line, not closed → park caller)
    Parked --> Open : write/2 delivers line → GenServer.reply to parked caller
    Parked --> Closed : close_write/1 → GenServer.reply :eof or partial to parked caller

    Open --> Closed : close_write/1
    Closed --> Closed : read_line/1 (drain buffer then :eof)
    Closed --> Closed : write/2 → {:error, :closed}

    Open --> [*] : destroy/1
    Closed --> [*] : destroy/1

Summary

Functions

Returns a specification to start this module under a supervisor.

Types

t()

@type t() :: %Bash.Pipe{pid: pid()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.