3 ms·
How about an `updateBalance(updateFn)` that is protected by a mutex: async function deduct(amt) { await updateBalance(balance => { if (balanc
by tlrobinson 7y ago
How about an `updateBalance(updateFn)` that is protected by a mutex:
async function deduct(amt) {
await updateBalance(balance => {
if (balance >= amt) {
return balance - amt;
} else {
throw new Error("not enough balance");
})
}