Jumar.EventBus.Producer (Jumar v0.1.0)

View Source

A GenStage implementation to produce events.

Usage

defmodule MyProducer do
  use Jumar.EventBus.Producer
end

Then you can use the producer module to produce events like so:

iex> MyProducer.produce(%Jumar.EventBus.Event{})

In many cases, you may want to customize the produce function and make it easier to use around you context. To do this, you can create a wrapper function that calls MyProducer.produce/1 with the event data.

defmodule MyProducer do
  use Jumar.EventBus.Producer

  def produce(event, %User{} = user) do
    MyProducer.produce(%Jumar.EventBus.Event{
      event: event,
      data: %{
        user: user
      }
    })
  end
end

And then call your produce/2 function like so:

  iex> MyProducer.produce(:user_created, %User{id: 1})

Summary

Functions

Produces an event to the event dispatcher. Will return :ok once the event has been dispatched or placed in queue waiting to be dispatched.

Starts the producer.

Functions

produce(mod, event)

@spec produce(module(), Jumar.EventBus.Event.t()) :: term()

Produces an event to the event dispatcher. Will return :ok once the event has been dispatched or placed in queue waiting to be dispatched.

start_link(args, opts \\ [])

Starts the producer.