# `Mojentic.Agents.SimpleRecursiveAgent.EventEmitter`
[🔗](https://github.com/svetzal/mojentic-ex/blob/v1.2.0/lib/mojentic/agents/simple_recursive_agent.ex#L129)

A GenServer-based event emitter that allows subscribing to and emitting events.

Subscribers receive events asynchronously via spawned tasks.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `emit`

```elixir
@spec emit(
  pid(),
  struct()
) :: :ok
```

Emits an event to all subscribers asynchronously.

## Parameters

- `pid` - The EventEmitter process
- `event` - The event struct to emit

## Examples

    EventEmitter.emit(emitter, %GoalSubmittedEvent{state: state})

# `start_link`

Starts the EventEmitter GenServer.

# `subscribe`

```elixir
@spec subscribe(pid(), module(), function()) :: reference()
```

Subscribes to an event type.

Returns a reference that can be used to unsubscribe.

## Parameters

- `pid` - The EventEmitter process
- `event_type` - The event module to subscribe to
- `callback` - Function to call when event is emitted

## Examples

    ref = EventEmitter.subscribe(emitter, GoalSubmittedEvent, fn event ->
      IO.inspect(event)
    end)

    EventEmitter.unsubscribe(emitter, ref)

# `unsubscribe`

```elixir
@spec unsubscribe(pid(), reference()) :: :ok
```

Unsubscribes from events using the reference returned by subscribe.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
