I have a pair matching algorithm, I add a function call to an array which acts as a queue and execute one by one to avoid conflicts when matching. I want something to keep and eye on the queue and execute when a function is added to the queue. Like a routine checking if the array has any element? Can I do this using something like
Edit: let me make my problem clear. I have a game using
socket.io where i match 2 users together and share some data with them Users click pair button and pair function is called. But the problem is that on high peak times user A gets match with B and B gets matched with C. This should not happen. So I queue the pairing function calls using and array. I want the array to execute each function call one after another. There will be times when the array will be queue empty for long time.