-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Bug fixes for Orleans Bank Account sample. #7019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fixes for Orleans Bank Account sample. #7019
Conversation
Balance now updates after Deposit or Withdraw operations. Withdraw decrements now instead of incorrectly incrementing.
Removing the immutability of the Balance class sets a bad precedent for this sample. The idea of immutability is to prevent the class of bugs where grain A makes a change to a instance, then sends it to grain B -- on the same silo -- and then makes another change to the instance, which, because it's a reference/byref, will change the instance in grain B also. |
@@ -34,7 +34,7 @@ public Task Withdraw(int amount) => | ||
$" This account has {balance.Value} credits."); | ||
} | ||
|
||
return balance with { Value = balance.Value + amount }; | ||
balance = balance.Value -= amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The balance =
part here is unnecessary - the balance
variable goes out of scope immediately after this statement
@oising I believe this is the correct change, due to how the transactions API works: The delegate passed to PerformUpdate receives a copy of state and it's expected to mutate it. |
Made Balance a class instead of a record as no benefit in using record here. Added Id attribute to Balance.Value so that it is serialized and to allow state to be persisted after a Withdrawal. Removed Reentrant attribute from AccountGrain as this could introduce race conditions when using Transactions.
07f28af
to
7a91f98
Compare
I fixed a couple of build errors in the commit. Also, I fixed the sample to allow the bank balance to actually persist the balance after a Withdrawal. |
Balance now updates after Deposit or Withdraw operations.
Withdraw decrements now instead of incorrectly incrementing.