Answer the question
In order to leave comments, you need to log in
How to cancel related action chains in an asynchronous application?
Hello! In web applications, it may be necessary to create functionality that displays actions without waiting for a server response. This is done to make the application feel "faster and more responsive".
For example, let's imagine that we have a "web face" of a file manager. We pressed the "create folder" button, and immediately saw that we had a folder created. Although a request is sent to the server to actually create it, and a response confirming that it was actually created may come in 20 seconds at all (in case of any network delays, for example). Or maybe an error response will come at all, and then our displayed "fake" folder will need to be hidden from the client, as if it never existed (of course, you can display a notification that an error occurred when creating the folder). It's all simple if we are talking about one action, and its cancellation. What if we are talking about a chain of actions?
Example:
1. The user clicked the "create folder" button and the new folder was immediately displayed in the web application.
2. The user moved a file from folder B to folder A.
3. The user performed some other operations not related to folder-A. For example, I renamed some other folder, created another file somewhere, etc.
4. An error message came from the server that folder A was not created.
5. Steps 1-2 should be cancelled. And the actions taken in step 3 should remain in effect, since they did not concern this error.
How would you implement this logic? Can you suggest any design pattern?
And if we also assume that folder-B was deleted in paragraph 3?
Answer the question
In order to leave comments, you need to log in
It's all simple if we are talking about one action, and its cancellation. What if we are talking about a chain of actions?In the scenario you describe, you simply don't need to use the optimistic interface.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question