Strom.Sink behaviour (strom v0.9.3)

View Source

Runs a given steam and call origin on each even in stream. By default it runs the stream asynchronously (in Task.async). One can pass true a the third argument to the Sink.new/3 function to run a stream synchronously.

## Example
iex> alias Strom.{Sink, Sink.WriteLines}
iex> sink = :strings |> Sink.new(WriteLines.new("test/data/sink.txt"), sync: true) |> Sink.start()
iex> %{} = Sink.call(%{strings: ["a", "b", "c"]}, sink)
iex> File.read!("test/data/sink.txt")
"a\nb\nc\n"

Sink defines a @behaviour. One can easily implement their own sinks. See Strom.Sink.Writeline, Strom.Sink.IOPuts, Strom.Sink.Null

Summary

Types

event()

@type event() :: any()

t()

@type t() :: %Strom.Sink{
  composite: term(),
  inputs: term(),
  opts: term(),
  origin: term(),
  outputs: term(),
  pid: term()
}

Callbacks

call(map, term)

@callback call(map(), term()) :: map() | no_return()

start(map)

@callback start(map()) :: map()

stop(map)

@callback stop(map()) :: map()

Functions

before_stop(origin)

build_stream(origin, stream)

call(flow, sink)

@spec call(Strom.flow(), t()) :: Strom.flow()

new(input, origin, opts \\ [])

@spec new(Strom.stream_name(), struct(), list()) :: t()

process_chunk(input_stream_name, chunk, outputs, atom)

@spec process_chunk(atom(), list(), Strom.flow(), any()) :: {Strom.flow(), false, nil}

start(sink)

@spec start(t()) :: t()

stop(sink)

@spec stop(t()) :: :ok