Skip to content
Advertisement

Start a Thread Timer directly

I want to trigger the self._runSequence() func directly after start the timer. This is my code:

JavaScript

If sequenceDuration is equal to 10 the func will be called 10 seconds later (as a normal timer I know..)

This is the RepeatedTimer Class:

JavaScript

What I already try:

JavaScript

But this give me an error when the timer trigger the __runSequence func that tell me I don’t give an argument to __runSequence() func.

Advertisement

Answer

If I understood you correctly, you want the function to be executed when the RepeatedTimer is initialized, and then periodically, right?

Instead of calling start in __init__, call _run. It calls start and execute the function.

JavaScript

Output

JavaScript

You can see that the first execution occurs before the initialization is complete.


Your first attempt was already correct.

JavaScript

The second would pass the result of self.__runSequence(sequence) (None unless you explicitly return something else) instead of the method itself.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement