Interval Event Handling¶
Interval Event Registry¶
-
class
CommonIntervalEventRegistry
¶ Bases:
sims4communitylib.services.common_service.CommonService
A registry that will run functions based on an amount of time.
Example usage: # This is an example showing how you may register your functions to run on intervals. class ExampleIntervalListener: # This function will run only once, after 200 milliseconds have passed. It will then stop listening. @staticmethod @CommonIntervalEventRegistry.run_once(ModInfo.get_identity().name, milliseconds=200) def _example_run_once(): pass # This function will run every 500 milliseconds. It will continue listening until the game is closed or until it is manually unregistered. @staticmethod @CommonIntervalEventRegistry.run_every(ModInfo.get_identity().name, milliseconds=500) def _example_run_every(): pass
-
register_dispatcher
(mod_identity, milliseconds, listening_func, run_once=False)¶ Manually register a new dispatcher to the registry.
Parameters: - mod_identity (CommonModIdentity) – The identity of the mod that owns the interval dispatcher.
- milliseconds (int) – How much time before the dispatcher runs the first time as well as how much time before it runs again.
- listening_func (Callable[.., Any]) – The function to invoke after the set amount of time.
- run_once (bool, optional) – If True, the dispatcher will run a single time, then be removed from the registry. If False, the dispatcher will continue running after the specified milliseconds and will repeat. Default is False.
Returns: A dispatcher that will trigger after a set amount of time or None if an error occurs while registering a dispatcher.
Return type: Union[CommonIntervalDispatcher, None]
-
static
run_every
(mod_identifier, milliseconds=1500)¶ Register a function to run in intervals of the specified time.
Note
The function will run in intervals every time the amount of time has occurred.
Parameters: - mod_identifier (Union[str, CommonModIdentity]) – The name or identity of the mod registering the listener.
- milliseconds (int) – The amount of time in milliseconds that must pass before the decorated function will be run.
Returns: A callable function wrapped that runs in intervals.
Return type: Callable[.., Callable[.., Any]]
-
static
run_once
(mod_identifier, milliseconds=1500)¶ Register a function to run a single time after a certain amount of time.
Note
A function decorated with this decorator will only run once.
Parameters: - mod_identifier (Union[str, CommonModIdentity]) – The name or identity of the mod registering the listener.
- milliseconds (int) – The amount of time in milliseconds that must pass before the decorated function will be run.
Returns: A callable function wrapped to run once.
Return type: Callable[.., Callable[.., Any]]
-