DoOnce
The DoOnce node is a flow control node that allows a portion of a spell to be executed only once, even if the node receives multiple triggers. It is useful for initializing variables, setting up one-time configurations, or performing actions that should only happen a single time regardless of how many times the spell is run.Inputs
flow(flow): The main flow input that triggers the node’s execution.reset(flow): An optional flow input that, when triggered, resets the DoOnce node, allowing the main flow to be executed again the next time it is triggered.
Outputs
flow(flow): The flow output that is triggered only once when the mainflowinput is triggered, unless the node is reset.
Configuration
The DoOnce node does not have any configuration options.Usage
- Add a DoOnce node to your spell.
- Connect the desired portion of your spell to the
flowoutput of the DoOnce node. - Trigger the
flowinput of the DoOnce node to execute the connected portion of the spell once. - If you need to allow the connected portion to execute again, trigger the
resetinput of the DoOnce node.
Example
Imagine you have a spell that processes data from a database and sends notifications based on certain conditions. You want to ensure that the database connection is established only once, even if the spell is triggered multiple times.- Add a DoOnce node to your spell.
- Connect the database connection logic to the
flowoutput of the DoOnce node. - Connect the rest of your spell (data processing and notification sending) after the database connection logic.
- Trigger the spell. The database connection will be established once, and the rest of the spell will execute normally.
- If the database connection is lost and needs to be re-established, trigger the
resetinput of the DoOnce node before triggering the spell again.
Best Practices
- Use the DoOnce node for initialization tasks, one-time configurations, or actions that should only be performed once in a spell’s lifecycle.
- Be mindful of when you need to reset the DoOnce node. Only use the
resetinput when necessary to avoid unintended behavior.
Common Issues
- Forgetting to reset the DoOnce node when needed can lead to unexpected behavior, as the intended “one-time” action will not be executed again until the node is reset.
- Resetting the DoOnce node too frequently can defeat its purpose and lead to inefficiencies in your spell.
