Skip to content

Consumer event list in handle_events return #36

@tsloughter

Description

@tsloughter

When reading the recent blog post I got confused by:

# We are a consumer, so we never emit events.
{:noreply, [], sleeping_time}

If a consumer can never emit events then why am I required to return a list of events for it to not emit?

Of course if I don't make this list of events an empty list I'll get an error:

 defp dispatch_events(events, %{type: :consumer} = stage) do
    :error_logger.error_msg('GenStage consumer ~p cannot dispatch events (an empty list must be returned): ~p~n', [name(), events])
    stage
end

But then if it knows the return value is always [] why do I have to tell it?

I'd argue that handle_events have the type:

{:noreply, new_state} |
{:noreply, new_state, :hibernate} |
{:noreply, [event], new_state} |
{:noreply, [event], new_state, :hibernate} |
{:stop, reason, new_state} when new_state: term, reason: term, event: term

And when handling mod.handle_events match on the type of process currently running since only consumer should be using the return type with no list of events.

Now I also notice that :noreply appears to be superfluous. You can never reply, so why say :noreply at all? It is an odd way to differentiate from :stop, so maybe unnecessary?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions