Strom.Source behaviour (strom v0.9.1)

View Source

Produces stream of events.

## Example with Enumerable
iex> alias Strom.Source
iex> source = :numbers |> Source.new([1, 2, 3]) |> Source.start()
iex> %{numbers: stream} = Source.call(%{}, source)
iex> Enum.to_list(stream)
[1, 2, 3]

## Example with file
iex> alias Strom.{Source, Source.ReadLines}
iex> source = :numbers |> Source.new(ReadLines.new("test/data/numbers1.txt")) |> Source.start()
iex> %{numbers: stream} = Source.call(%{}, source)
iex> Enum.to_list(stream)
["1", "2", "3", "4", "5"]

## If two sources are applied to one stream, the streams will be concatenated (Stream.concat/2)
iex> alias Strom.{Source, Source.ReadLines}
iex> source1 = :numbers |> Source.new([1, 2, 3]) |> Source.start()
iex> source2 = :numbers |> Source.new(ReadLines.new("test/data/numbers1.txt")) |> Source.start()
iex> %{numbers: stream} = %{} |> Source.call(source1) |> Source.call(source2)
iex> Enum.to_list(stream)
[1, 2, 3, "1", "2", "3", "4", "5"]

Source defines a @behaviour. One can easily implement their own sources. See Strom.Source.ReadLines, Strom.Source.Events, Strom.Source.IOGets

Summary

Types

event()

@type event() :: any()

t()

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

Callbacks

call(map)

@callback call(map()) :: {[term()], map()} | {:halt, map()} | no_return()

start(map)

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

stop(map)

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

Functions

build_stream(origin)

call(flow, source)

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

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

@spec new(Strom.stream_name(), struct() | [event()] | Strom.stream(), list()) :: t()

process_chunk(input_stream_name, chunk, outputs, atom)

start(source)

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

stop(source)

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