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

Add option for Actors to delay a response #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

RedKinda
Copy link
Contributor

Sometimes it is useful to delay sending a response, but still allow the actor to process other messages. It can be useful in cases, where the actor needs to persist some data or make external requests, does not need a &mut self but the message response does depend on result of the persistence operation. In this case it would be possible to do something like tokio::spawn(async move { persist().await; sender.send(Ok(())) } );

This PR exposes the response oneshot sender to the actor through a new method, which actor definitions may override if they wish to. Now, I am not sure if the option to process other messages before sending a response breaks soundness or creates other issues, but I did not find any. One small issue I found is that measuring the time for metrics purposes might be misleading, if the response is actually delayed, as it measures the time for the handle() function to return, not actual sending of the response.

Let me know if there are any issues :)

@RedKinda
Copy link
Contributor Author

RedKinda commented Jul 23, 2023

Actually, I realized this is not actually great, since the handle method needs to be implemented as well, which kind of breaks it. Not sure how about fixing that

@RedKinda RedKinda force-pushed the dev/delayed_handler branch 2 times, most recently from 4003378 to a5a94aa Compare November 22, 2023 21:50
@RedKinda RedKinda force-pushed the dev/delayed_handler branch from a5a94aa to 2f928b7 Compare May 2, 2024 11:50
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.

1 participant