Background: I have the game tic tac toe and I have an created an interactive web app to try and teach people the best moves. The AI which works out the best moves is on the front end but it takes a few seconds to run. I want to run the code to 'solve' the game immediately after initially rendering the page but I also want it to stop whenever a user clicks a button etc. In Java I would simply set up a new thread and put it on there but I understand JS is single threaded? I know this is possible as I have seen it demonstrated in other sites such as https://lichess.org/analysis. I'm interested in the principle not the solution so please don't suggest things like 'make your AI more efficient' or 'use a hashtable'.
Question: How do I set a computationally long task running (in the 'background') in React such that the UI elements are not bottlenecked by it?
Aucun commentaire:
Enregistrer un commentaire