Created
June 24, 2017 13:19
-
-
Save tomliversidge/346a4ea06475b0f6b360c724af6c9880 to your computer and use it in GitHub Desktop.
Saga 2.3
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
| class AccountProxy : IActor | |
| { | |
| private readonly PID _account; | |
| private readonly Func<PID, object> _createMessage; | |
| public AccountProxy(PID account, Func<PID, object> createMessage) | |
| { | |
| _account = account; | |
| _createMessage = createMessage; | |
| } | |
| public Task ReceiveAsync(IContext context) | |
| { | |
| switch (context.Message) | |
| { | |
| case Started _: | |
| _account.Tell(_createMessage(context.Self)); | |
| context.SetReceiveTimeout(TimeSpan.FromMilliseconds(100)); | |
| break; | |
| case OK msg: | |
| context.CancelReceiveTimeout(); | |
| context.Parent.Tell(msg); | |
| break; | |
| case Refused msg: | |
| context.CancelReceiveTimeout(); | |
| context.Parent.Tell(msg); | |
| break; | |
| // These represent a failed remote call | |
| case InternalServerError _: | |
| case ReceiveTimeout _: | |
| case ServiceUnavailable _: | |
| throw new Exception(); | |
| } | |
| return Actor.Done; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment