Current section

Files

Jump to
exd lib exd sink.ex
Raw

lib/exd/sink.ex

defmodule Exd.Sink do
@moduledoc """
Defines a source
## Options
* `:adapter` - The source adapter module and options
* `:concurrency` - The number of concurrent source connections
## Usage
defmodule PersonSource do
use Exd.Source,
adapter: {
Exd.Sources.File,
file_path: "test/support/fixtures/people.json"
}
end
"""
use GenStage
def start_link(opts) do
GenStage.start_link(__MODULE__, opts )
end
@impl true
def init(opts) do
{adapter, adapter_opts} = Keyword.fetch!(opts, :adapter)
{:ok, sink_state} = adapter.init(adapter_opts)
{:consumer, {adapter, sink_state}}
end
@impl true
def handle_events(events, _from, {adapter, sink_state}) do
adapter.handle_into(events, sink_state)
{:noreply, [], {adapter, sink_state}}
end
end