Skip to content

Instantly share code, notes, and snippets.

View tomliversidge's full-sized avatar

Tom Liversidge tomliversidge

  • Tallinn, Estonia
View GitHub Profile
case Refused msg:
_behavior.Become(RollingBackDebit)
context.SpawnNamed(TryCredit(_from, +_amount), "RollbackDebit");
case OK msg:
_logger.Log("Success!")
StopAll(context);
private async Task AwaitingCreditConfirmation(IContext context)
{
switch (context.Message)
{
//...
case OK msg:
_logger.Log("Success!")
StopAll(context);
break;
case Refused msg:
case Terminated _:
_logger.Log("Transfer status unknown. Escalate")
StopAll(context);
case Refused _:
_logger.Log("Transfer failed. System consistent")
StopAll(context);
case OK _:
_behavior.Become(AwaitingCreditConfirmation);
context.SpawnNamed(TryCredit(_to, +_amount), "CreditAttempt");
private Task AwaitingDebitConfirmation(IContext context)
{
switch (context.Message)
{
case OK _:
_behavior.Become(AwaitingCreditConfirmation);
context.SpawnNamed(TryCredit(_to, +_amount), "CreditAttempt");
break;
case Refused _:
_logger.Log("Transfer failed. System consistent")
private async Task Starting(IContext context)
{
if (context.Message is Started)
{
context.SpawnNamed(TryDebit(_from, -_amount), "DebitAttempt");
_behavior.Become(AwaitingDebitConfirmation);
}
}
private Props TryDebit(PID targetActor, decimal amount) => Actor
public async Task ReceiveAsync(IContext context)
{
await _behavior.ReceiveAsync(context);
}
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;
}