Skip to content

Instantly share code, notes, and snippets.

@tomliversidge
Created June 24, 2017 13:19
Show Gist options
  • Save tomliversidge/346a4ea06475b0f6b360c724af6c9880 to your computer and use it in GitHub Desktop.
Save tomliversidge/346a4ea06475b0f6b360c724af6c9880 to your computer and use it in GitHub Desktop.
Saga 2.3
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