I'm developping a multiplayer game and I want to connect two players that don't know each other with a research in the database. So I thinked about doing it like this:
- The player that want to play with a random opponent clicks a button on my app.
- When the button is pressed I control in the database in my 'randomPlayers' table if there is someone to play with
- If there aren't player stored in the table I put the nickname in the database waiting for someone that want to play
- If, instead, there is someone stored in the database I take the first nickname (ordered by timestamp) and I play with it.
My question is: How I can be sure that two players that search a random player in the same moment take two differents players and not the same because SELECT return the same player ? In other words is SELECT synchronous or asynchronous ?