Imagine a javascript class called MealAdvisor that keeps track of available ingredients and equipment and calculates the best possible meal that can be made with the available resources. It has methods that can be called like:
Suppose that it can sometimes take time to execute the method calls of the advisor. Instead of freezing the user interface, the calls should be queued and executed in order in the background while the user interface shows some waiting indicator and new calls can be added to the queue. Whenever the advisor has caught up and the queue is empty, it should tell the user interface so that it can show a result.
Which is the best way to modify MealAdvisor to support this? It should be usable in a content script that is added to a particular website using a chrome extension.