dawdle v0.5.1 Dawdle.Handler behaviour View Source

Defines a handler for queued events.

To define an event handler, use Dawdle.Handler and provide a list of event types (structs) that you wish to handle. Then, override the callback handle_event/1.

Examples

defmodule MyApp.TestEvent do
  defstruct :foo, :bar
end

defmodule MyApp.TestEventHandler do
  use Dawdle.Handler, only: [MyApp.TestEvent]

  alias MyApp.TestEvent

  def handle_event(%TestEvent{foo: 1}) do
    # Do something...
  end

  def handle_event(%TestEvent{bar: 2}) do
    # Do something else...
  end

  def handle_event(%TestEvent{}) do
    # Default case
  end
end

Link to this section Summary

Callbacks

This function is called when Dawdle pulls an event of the appropriate type from the queue.

Link to this section Callbacks

Link to this callback

handle_event(event) View Source
handle_event(event :: Dawdle.event()) :: any()

This function is called when Dawdle pulls an event of the appropriate type from the queue.

It will only be called with events specified in the use Dawdle.Handler statement. The function is executed for its side effects and the return value is ignored.