I think have a misunderstanding of how TCP sockets work in Node!
My server is receiving data from a client, processing the data, and sending a response. However, while processing the response, another 'data' event fires .... which I wasn't really expecting - I figured that the first handler would complete, before further events trigger. Probably a bad assumption on my part, but I can't find much documentation that shows examples other than very trivial ones.
Are there any elegant solutions to this problem? I will probably have to perhaps use a separate loop that polls for data being available in a FIFO type Buffer, I prefer an event based mechanism, but perhaps I can't in this case.
// Accept a connection from a client ...
_server.on('connection', async function(socket){
// Some new data has arrived - this can fire while
// still processing the previous event
socket.on('data', async function(data){
// Process the data ... DB updates etc.
});
});