Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions orleans/BankAccount/AccountTransfer.Grains/AccountGrain.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using AccountTransfer.Interfaces;
using Orleans.Concurrency;
using Orleans.Transactions.Abstractions;

namespace AccountTransfer.Grains;

[GenerateSerializer, Immutable]
public record class Balance
[GenerateSerializer]
public class Balance
{
public int Value { get; init; } = 1_000;
[Id(0)]
public int Value { get; set; } = 1_000;
}

[Reentrant]
public sealed class AccountGrain : Grain, IAccountGrain
{
private readonly ITransactionalState<Balance> _balance;
Expand All @@ -21,7 +20,7 @@ public AccountGrain(

public Task Deposit(int amount) =>
_balance.PerformUpdate(
balance => balance with { Value = balance.Value + amount });
balance => balance.Value += amount);

public Task Withdraw(int amount) =>
_balance.PerformUpdate(balance =>
Expand All @@ -34,7 +33,7 @@ public Task Withdraw(int amount) =>
$" This account has {balance.Value} credits.");
}

return balance with { Value = balance.Value + amount };
balance.Value -= amount;
});

public Task<int> GetBalance() =>
Expand Down
Loading