|
| 1 | +--- |
| 2 | +title: Periodic [Action] |
| 3 | +sidebar_position: 3 |
| 4 | +--- |
| 5 | + |
| 6 | +# Periodic Action |
| 7 | + |
| 8 | +Periodic execution of logic refers to running a specific block of code or a set of actions at |
| 9 | +regular, defined intervals. This is useful for tasks that need to be repeated continuously or at |
| 10 | +specific time intervals. |
| 11 | + |
| 12 | +## Use-cases |
| 13 | + |
| 14 | +- For tasks that need regular updates, such as fetching data from a server, monitoring system |
| 15 | + health, or updating a user interface. |
| 16 | +- In scenarios where periodic checks or maintenance tasks are required (e.g., cleaning up |
| 17 | + temporary files, sending periodic notifications). |
| 18 | +- Implementing polling mechanisms for checking changes in state or data. |
| 19 | + |
| 20 | +## Start Periodic Action |
| 21 | + |
| 22 | +To create a periodic action workflow, add the **Start Periodic Action** action either on the **On |
| 23 | +Page Load** action trigger of your page or on any widget that should start the periodic action. |
| 24 | + |
| 25 | +The properties of the Periodic Action look like this: |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +## Stop Periodic Action |
| 30 | + |
| 31 | +You can call the **Stop Periodic Action** action from anywhere on the page or component to stop |
| 32 | +one or multiple |
| 33 | +periodic actions. |
| 34 | + |
| 35 | +:::danger[Dont forget to stop the Periodic Actions] |
| 36 | +Stopping a periodic action is crucial to prevent unnecessary resource consumption and potential |
| 37 | +performance issues. It ensures that tasks do not continue running in the background when they are no |
| 38 | +longer needed, which can help maintain the efficiency and responsiveness of your application. |
| 39 | +::: |
| 40 | + |
| 41 | +### Periodic Action vs Timer |
| 42 | + |
| 43 | +| Feature | Timer Widget | Periodic Action | |
| 44 | +|-------------|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------| |
| 45 | +| **Purpose** | Used for single or non-repetitive timing events, often within user interfaces. | Used for repetitive tasks that need to run at regular intervals. | |
| 46 | +| **Usage** | To set a countdown timer, start/stop actions based on user input, or trigger actions after a specific duration. | For background tasks, monitoring, regular updates, and periodic checks. | |
| 47 | +| **Example** | Countdown timer in a quiz application. | Fetching new messages from a server every 5 minutes. | |
| 48 | + |
| 49 | + |
| 50 | +### Periodic Actions vs Loops |
| 51 | + |
| 52 | +| Feature | Periodic Actions | Loops | |
| 53 | +|---------------------------|-----------------------------------------------------------------------------|------------------------------------------------------------------------| |
| 54 | +| **Purpose** | To execute a task at regular, defined intervals. | To execute a task repeatedly until a condition is met. | |
| 55 | +| **Execution Frequency** | Executes at specified time intervals (e.g., every 60 seconds). | Executes continuously until the loop condition is false. | |
| 56 | +| **Use Case** | Suitable for tasks needing regular updates, such as fetching new data. | Suitable for tasks requiring iteration over collections or repeated checks. | |
| 57 | +| **Control** | Can be started and stopped easily, allowing for controlled execution. | Runs until a break condition is met or the loop is explicitly stopped. | |
| 58 | +| **Resource Management** | Efficient, as it allows idle time between executions. | Can be resource-intensive if not managed properly, as it runs continuously. | |
| 59 | +| **Examples** | Fetching new offers from a server every 5 minutes. | Iterating over a list of items to process them one by one. | |
0 commit comments