State Status
As we have mentioned, Weld allows developers to create complex and nested state-machines. Weld makes it easy to check the status of state-machines' states and take actions based on whether a state is active or inactive.
In order to check if the specific state is active or inactive in the current execution cycle, Weld has the isActive(state_name)
and isInactive(state_name)
API calls. These calls return a boolean
that indicates if a state is active or inactive.
Tip
State Status API allows you to check the status of states in other threads.
Usage¶
In order to use the state status APIs, you should include the target state's name as the call parameter. It is important that the name is unique, otherwise, the code generator cannot determine the target state and it will result in an error.
In order to specify the target state, you can chain the descendants of a parent after the parent's name, using the dot .
operator. For example, if you want to target "child_name" which is a child of "parent_name" state, you can use isActive(parent_name.child_name)
. In this way, you can uniquely identify the target state and prevent errors.
Also, this API works for states in other threads as well. So, if you want to check the status of a state that is in another thread, you can simply use isActive(thread_name.parent_name.child_name)
and check the status of the child target state.