Overview
This article explains the risks associated with executing asynchronous requests in Actions without awaiting the promise. It outlines the potential for erratic behavior and provides recommendations for handling these scenarios.
Applies To
- Actions
- Asynchronous Promises
Cause
To expedite processes, such as a post-login event, an administrator may attempt to send data to an external endpoint from an Action without awaiting the fetch
request’s promise. While this allows the login to complete more quickly, it leaves an asynchronous operation running without proper handling within the Action’s execution lifecycle, which can lead to issues.
Solution
- It is not recommended to execute asynchronous requests from Actions without awaiting the corresponding promise. Long-running requests that do not time out quickly can continue running and collide with new executions of the Action, which can cause erratic behavior.
- If this practice is employed, the associated risks and errors must be handled directly. The following practices should be implemented to mitigate potential issues:
- Ensure the external service is fast and responsive.
- Enforce short timeout periods for any requests made from the Action.
- Queue the data handling at the external service to increase speed and responsiveness.
- Implement error handling within the Action to ensure it does not fail asynchronously.