> For the complete documentation index, see [llms.txt](https://docs.emobiq.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.emobiq.com/emobiq-client/006-actions-and-visual-logic/logic-flow-sequence-and-control/asynchronous-actions-and-callbacks/best-practices.md).

# Best Practices

Asynchronous logic blocks play a crucial role in enhancing your app's responsiveness and efficiency. Here are some best practices to consider when utilizing these blocks on eMOBIQ.

## 1. Prioritize User Experience

* **Keep UI Responsive**: Design your logic flows in a way that prevents the app's user interface from freezing or becoming unresponsive during asynchronous operations. This ensures a seamless experience for users interacting with your app.

## 2. Use Callback Logic Wisely

* **Assign Callbacks Strategically**: When using callback logic to sequence actions after asynchronous tasks, ensure that your logic is well-structured. Assign callbacks only when their execution truly depends on the outcome of the asynchronous operation.

## 3. Manage Error Handling

* **Implement Error Handling**: Asynchronous operations can encounter errors, such as network failures or invalid data. Incorporate error handling logic to gracefully manage these scenarios and provide users with meaningful feedback.

## 4. Optimize Performance

* **Minimize Unnecessary Calls**: Avoid making redundant asynchronous calls. Use eMOBIQ tables to store and reuse fetched data when appropriate, reducing unnecessary network requests.
* **Set Reasonable Intervals**: If using timers or intervals within your asynchronous logic, set them according to the needs of your app. Avoid excessively short intervals that might lead to unnecessary load or increased network traffic.

## 5. Beware of Race Conditions

* **Caution with Shared Variables**: When using variables shared between asynchronous operations within the same callback, be cautious of race conditions. A race condition occurs when multiple operations try to modify the same variable concurrently, potentially leading to unexpected results. Consider isolating variable usage when necessary.

## 6. Copying Values to Callback Logic Blocks

* **Sharing Data with 'Extra'**: In some cases, you can pass information from a source asynchronous logic block to a callback logic block using a construct called 'extra'. This value is copied and made available for use in the callback logic block. Since this value is copied, there is no memory overwrite of any variable.

## 7. Simplify Logic Flows

* **Visualize Logic Flows**: Leverage the visual nature of eMOBIQ to create clear and coherent logic flows. Use comments to distinguish asynchronous blocks and their interactions.

## 8. Test and Iterate

* **Test for Scenarios**: Thoroughly test your logic flows for various scenarios, including successful responses and potential errors. This helps identify any unexpected behavior and ensures the logic works as intended.
* **Iterate Based on User Feedback**: Continuously gather feedback from users of your application and iterate on your asynchronous logic blocks. This ensures that your blocks meet real-world usage needs and expectations.

## 9. Document and Educate

* **Provide Clear Documentation**: Create user-friendly documentation that explains the purpose, usage, and potential challenges of asynchronous logic blocks. Help users understand when and how to use these blocks effectively.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.emobiq.com/emobiq-client/006-actions-and-visual-logic/logic-flow-sequence-and-control/asynchronous-actions-and-callbacks/best-practices.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
