Created
June 24, 2017 13:17
-
-
Save tomliversidge/5001e29ee5f1ee672520c5a9b80bef8b to your computer and use it in GitHub Desktop.
Saga 2.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Task AdjustBalance(PID replyTo, decimal amount) | |
| { | |
| if (RefusePermanently()) | |
| { | |
| _processedMessages.Add(replyTo, new Refused()); | |
| replyTo.Tell(new Refused()); | |
| } | |
| if (Busy()) | |
| replyTo.Tell(new ServiceUnavailable()); | |
| var behaviour = DetermineProcessingBehavior(); | |
| if (behaviour == Behavior.FailBeforeProcessing) | |
| return Failure(replyTo); | |
| // simulate potential slow service | |
| Thread.Sleep(_random.Next(0, 150)); | |
| _balance += amount; | |
| _processedMessages.Add(replyTo, new OK()); | |
| if (behaviour == Behavior.FailAfterProcessing) | |
| return Failure(replyTo); | |
| replyTo.Tell(new OK()); | |
| return Actor.Done; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment