Skip to content

add queued message handler example#23

Merged
lulf merged 2 commits intodrogue-iot:mainfrom
jamessizeland:qmh-example
Feb 25, 2025
Merged

add queued message handler example#23
lulf merged 2 commits intodrogue-iot:mainfrom
jamessizeland:qmh-example

Conversation

@jamessizeland
Copy link
Contributor

This is an example pattern that I like to use for actors. I'm not sure if its different enough to the other examples but I thought I'd throw it up here for your interest.

Copy link
Contributor

@petekubiak petekubiak left a comment

Choose a reason for hiding this comment

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

LGTM!

async fn act(&mut self, msg: Message) {
match msg {
Message::Act(n) => {
// Set the starting count and begin the schedule
Copy link
Contributor

Choose a reason for hiding this comment

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

So the actor is spawned with a count defined by config.starting_count, then the Act message provides a value which is added to that starting count, then on each tick of the scheduler the count is increased by 1 and printed to the console?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep that's it, a fairly basic example. These examples run on OS too.

I'm wondering what boilerplate can be reduced with macros... Maybe a derive on the Actor private data struct.

Copy link
Member

@lulf lulf left a comment

Choose a reason for hiding this comment

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

Thanks, nice example!

@lulf lulf merged commit a22eb3a into drogue-iot:main Feb 25, 2025
1 check passed
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