As I understand the non-blocking concept this could happen. But the one threat architecture of node.js made me doubt about it.
Let's say I have two endpoints on my HTTP server:
app.get('/one', () => {
global.counter = 'A'
global.counter += 'A'
global.counter += 'A'
...
})
app.get('/two', () => {
global.counter = 'B'
global.counter += 'B'
global.counter += 'B'
...
})
What happen if the server receive two request almost at the same time. Can global.counter
end up with a mix of A
and B
?
What about using async/await
like global.counter += await getB()
?