Old example:
Syntax: Select all
from listeners.tick import tick_delays
def delayed_callback(x, y):
print('Delayed callback', x, y)
delay = tick_delays.delay(3, delayed_callback, 'test', 123)
# Cancel the delay
delay.cancel()
New example:
Syntax: Select all
from listeners.tick import Delay
def delayed_callback(x, y):
print('Delayed callback', x, y)
delay = Delay(3, delayed_callback, 'test', 123)
# Prints True
print(delay.running)
# Cancel the delay
delay.cancel()
# Prints False, because it has been cancelled and isn't running anymore
print(delay.running)
# Sometimes you might also want to cancel the delay and call the callback immediately.
# This can be done by simply calling the Delay object
delay()