Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invasionofsmallcubes/24996d66819e49f60f99083ede31a314 to your computer and use it in GitHub Desktop.
Save invasionofsmallcubes/24996d66819e49f60f99083ede31a314 to your computer and use it in GitHub Desktop.
Hi,
I watched your presentation about CQRS and Erlang at NDC Oslo.
Before I ask you something, please now I never used Erlang so it could my
lack of knowledge on the language that led me to ask you this question.
I have a question about the demo code:
`
attempt_command({withdraw_money, Amount}, State) ->
NewBalance = State#state.balance - Amount,
Id = State#state.id,
Event = case(NewBalance < 0) of
false ->
#bank_account_money_withdrawn{id=Id, amount=Amount,
new_balance=NewBalance,transaction_date=erlang:localtime()};
true ->
#bank_account_payment_declined{id=Id,amount=Amount,
transaction_date=erlang:localtime()}
end,
apply_new_event(Event, State);
```
The first line is where you try to withdraw money. How is handled here the concurrency?
I mean I can have two concurrent operations on the same bank account but here I don't see
this check here. Is the system running all commands sequentially so that state doesn't get corrupted?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment