dolu on Nostr: I don't know the context of your post, but of course mutex is useful in JS. If you ...
I don't know the context of your post, but of course mutex is useful in JS.
If you have an async function inside your function, you could need a mutex
Simple example is spend money, call this function 2 times in a short time and your user could spend money he doesn't have
async function spendMoney(amount) {
const balance = await getBalance()
if (balance > amount)
await spend(amount)
}
Published at
2025-02-03 14:42:32Event JSON
{
"id": "6a0935bf0fd0a7af5b66eb02fa3ce70324fcc17f677960663e7144a2f7dda6f9",
"pubkey": "59b96df8d8b5e66b3b95a3e1ba159750a6edd69bcbba1857aeb652a5b208bd59",
"created_at": 1738593752,
"kind": 1,
"tags": [
[
"e",
"d9570ec31b539ecc24bff5055396ac4733434aecd805517c6a975e1600d52e57",
"wss://ditto.pub/relay",
"root",
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"
],
[
"e",
"d9570ec31b539ecc24bff5055396ac4733434aecd805517c6a975e1600d52e57",
"wss://ditto.pub/relay",
"reply",
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"
],
[
"p",
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
"wss://ditto.pub/relay"
]
],
"content": "I don't know the context of your post, but of course mutex is useful in JS.\nIf you have an async function inside your function, you could need a mutex\n\nSimple example is spend money, call this function 2 times in a short time and your user could spend money he doesn't have\n\nasync function spendMoney(amount) {\n const balance = await getBalance()\n if (balance \u003e amount) \n await spend(amount)\n}",
"sig": "7ee12a85dafd512f367bcb2fb47cd66758f93063c14611b62961f823e0a5e5a949e9c06d071ae013f27f8fcb8f6a6f38614d7e844080db34d450307d14629d28"
}