I have a scenario where one user would like to play game with someone random online.
Here are basic requirements
- select one random user
- send a request to that user via channel
- if user doesnt respond within 10 seconds, try to connect to other user
- if user accepts within 10 seconds, stop sending requests and start the game
- if user rejects the game request, lets say after 2 seconds search for another user
Here is what I have tried:
- I start a task ie Task.async -> search_palyer end
- search_palyer will first check if the last request was accepted or rejected
- if last request was not accepted, it will fetch another random player and send request
- called timer.sleep for 10 seconds
- recursive call to same function untill it succeeds
This works but the problem is, if the palyer to which I send request rejects immediately my task will sit idle for 9-10 seconds and wont do anything. I want to find player as soon as possible. Player gets a bad experience this way as he/she has to wait longer