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

Akka style Become and Unbecome #97

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

Conversation

akatashev
Copy link

@akatashev akatashev commented May 19, 2020

Based on this issue: #38

This PR adds two methods to the standard Actor class:

  1. Method _become(self, func, *args, discard_old=True) changes message handing behaviour to a specified function.
  • funcparameter is a callable function that should be executed on message receive.
  • *args parameter allows us to pass any values we need to the function and to avoid using "mutable" class properties to keep actor state (surely, there is no immutability in Python, but still class properties are not used).
  • discard_old=True parameter says whether it should to replace actual behaviour with this new handler completely or it should stash handlers in a handlers stack to be able to return back to them.
  1. Method _unbecome(self) changes actor's message processing strategy to the previous one.
  • If _become was used with discard_old=True option, _unbecome switches behaviour to the standard on_receive method.
  • If _become was used with discard_old=False option and there are n message handlers in stack, behaviour will change to the handler n-1.
  • If _become wasn't used, and actual behaviour is the default one, nothing happens.

These methods allow to model an FSM with an actor, using _become and _unbecome to switch between states.

@codecov
Copy link

codecov bot commented May 22, 2020

Codecov Report

Merging #97 into develop will increase coverage by 0.26%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #97      +/-   ##
===========================================
+ Coverage    95.37%   95.63%   +0.26%     
===========================================
  Files           13       13              
  Lines          562      573      +11     
===========================================
+ Hits           536      548      +12     
+ Misses          26       25       -1     
Impacted Files Coverage Δ
pykka/_actor.py 97.03% <100.00%> (+1.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c4c9a7...deda7f7. Read the comment docs.

Base automatically changed from develop to main March 6, 2021 18:16
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.

None yet

1 participant