This implements a new timers submodule in bpy.app.
Currently two operations are supported:
- add(function: Callable[, Union[None, float]], *, first_interval: float = 0): This will register a new timer. Does someone have a better name for the second parameter? first_interval is zero by default to avoid unnecessary duplication of information. E.g. when you want your function to be executed once every minute, it should not be necessary to write 60 in two places.
The callback function is expected to return None or float. If None is returned or an exception is raised or some invalid type is returned, the timer will be unregistered. If float is returned, the function will be executed again in that many seconds. If the number is <= 0, the function will be executed in the next main loop iteration.
- remove(function): Remove the timer. Throws an exception, if the function is currently not registered.
Currently it takes O(n) time to remove one timer, where n is the number of registered functions.
This can be problematic if someone registers thousands of timers and wants to remove
them all in a short period of time. However, it felt like making handling this case
better is not worth the complexity right now. I might add this later.