SoftwareTransaction is an implementation of software transaction memory,
described in greater detail here.
The idea is that you can have a block that contains multiple reads
and writes, then we'll commit all those changes as a single transaction,
automatically retrying as necessary.
Inside the .transact() block, all reads and writes must go through
the transaction, not the client, or they won't be tracked.
For example, this is a safe way to move 'money' between bank/account1 and
bank/account2:
constamount = 42;
etcd3.stm().transact(tx=> { returnPromise.all([ tx.get('bank/account1').number(), tx.get('bank/account2').number(), ]).then(([balance1, balance2]) => { if (balance1 < amount) { thrownewError('You do not have enough money to transfer!'); }
transact runs the function with the current configuration. It will be
retried until the transaction succeeds, or until the maximum number of
retries has been exceeded.
SoftwareTransaction is an implementation of software transaction memory, described in greater detail here. The idea is that you can have a block that contains multiple reads and writes, then we'll commit all those changes as a single transaction, automatically retrying as necessary.
Inside the
.transact()block, all reads and writes must go through the transaction, not the client, or they won't be tracked.For example, this is a safe way to move 'money' between
bank/account1andbank/account2:(Note: the author does not condone using etcd for your banking infrastructure)