Introduce an account with Ref ie Ref for each account and complete the money transfer operation in dosync operations. Also, make sure that you do not perform any side effect operation (other than those specified in Refs) in the dosync operation, since it can be repeated in case of conflict when updating links.
Update: If you have the number of corrected accounts, you can use ref vectors where each ref in the vector is an account and each account is identified by an index in the vector.
Example:
(def total-accounts 100) (def accounts (vec (map (fn [_] (ref 100)) (range total-accounts))))
If you need to dynamically add new accounts and identify them by name, you can use a hash map where the key is the account identifier (unique value) and the value is Ref for the account balance. You will need to wrap this card in Ref if you want to perform parallel operations to add / remove accounts from multiple threads.
Ankur source share