Asynchronous operations can bring a better customer experience, but it also adds to the troubles of developers. Currently, asynchronous operations generated using WebService mainly have the following problems:
- For Asynchronous fetch, it is best not to make logical judgments in client code.
- Methods that need to be loaded in order, resulting in reduced code readability.
To address the above issues, I have two solutions based on my existing development experience:
- There is no relationship between client fetch methods. I use the client-side counting method, that is, to define a global variable, add this variable to 1 in the asynchronous completed method, and determine whether it is equal to the expected number of times of development, if they are equal, all data is loaded.
- For the number fetch method that must have a certain order, you need to increase the readability of the Code. I will write each fetch method into a single method and input an action delegate. In this way, only one entry needs to be determined during development, and the logic is handed over to the completed processing of each method.