View Source Strom.Sink behaviour (strom v0.8.1)

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"), 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

@type event() :: any()
@type t() :: %Strom.Sink{
  name: term(),
  origin: term(),
  pid: term(),
  stream: term(),
  sync: term(),
  task: term()
}

Callbacks

@callback call(map(), term()) :: {:ok, {term(), map()}} | {:error, {term(), map()}}
@callback start(map()) :: map()
@callback stop(map()) :: map()

Functions

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

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

new(name, origin, sync \\ false)

View Source
@spec new(Strom.stream_name(), struct(), boolean()) :: t()
@spec start(t()) :: t()
@spec stop(t()) :: :ok