Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Adds ability to associate arbitrary data with a Cro::Message #38

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/Cro/Message.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
# application is processing. It might be a message from a message queue, a
# ZeroMQ message, a HTTP request, a HTTP response, etc.
role Cro::Message {
also does Associative;
Copy link

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It's the easiest way to implement what I need.


# cw: For OOB attributes associated with the messages. Consider
# that there is no way to know who the message is from,
# or where it is supposed to go.
has %!attributes;
Copy link

@lizmat lizmat Jul 3, 2024

Choose a reason for hiding this comment

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

Why not has %!attributes handles <keys pairs values AT-KEY EXISTS-KEY> and possibly extend on that when needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should work.


method keys { %!attributes.keys }
method pairs { %!attributes.pairs }
method values { %!attributes.values }

method AT-KEY (\k) is rw {
%!attributes{k}
}

method EXISTS-key (\k) {
%!attributes{k}:exists;
}


# Provides trace output for use with CRO_TRACE=1 and `cro trace ...`.
# Should include a developer-friendly view of the message. The default is
# just to show the message type
Expand Down