Skip to content

Conversation

@erikrozendaal
Copy link
Member

@erikrozendaal erikrozendaal commented Jan 16, 2026

Raise an error to notify the developer to use next instead of
return to skip (part of) the message handler code.

Use define_method to make event handler blocks behave like
normal Ruby methods, so using return just returns from the
message handler body and does not exit the event handling loop
of the message dispatcher.

In Ruby the return from a block returns from the enclosing
method. Since we capture blocks when registering handlers with on
and then execute them later using instance_exec this causes
unintuitive behaviour, as subsequent handlers are no longer executed
when a handler uses return.

Raise an error to notify the developer to use `next` instead of
`return` to skip (part of) the message handler code.

In Ruby the `return` from a block returns from the enclosing
method. Since we capture blocks when registering handlers with `on`
and then execute them later using `instance_exec` this causes
unintuitive behaviour, as subsequent handlers are no longer executed
when a handler uses `return`.
@erikrozendaal erikrozendaal force-pushed the return-from-handler-should-not-skip-subsequent-handlers branch from 0941652 to b1adeed Compare January 16, 2026 15:13
@erikrozendaal erikrozendaal changed the title Returning from a message handler should not skip subsequent handlers Early exit from a message handler should not skip subsequent handlers Jan 16, 2026
This way `return` behaves as expected (returning only from the
handler, instead of breaking out of the loop calling all handlers).
Copy link
Member

@lvonk lvonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@erikrozendaal erikrozendaal merged commit 1395495 into master Jan 19, 2026
5 checks passed
@erikrozendaal erikrozendaal deleted the return-from-handler-should-not-skip-subsequent-handlers branch January 19, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants