tick_delays changes

Discuss API design here.
User avatar
Ayuto
Project Leader
Posts: 1619
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

tick_delays changes

Postby Ayuto » Sat Jan 02, 2016 3:29 pm

We have updated our delaying mechanism to implement the changes proposed in issue #95. There were also a few issues e.g. with cancelling a delay (reported in the issue) and delays continued running after unloading the plugin which created the delay. These issues are now fixed!

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()
User avatar
iPlayer
Developer
Posts: 533
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Tue Jan 05, 2016 7:15 pm

Also worth mentioning that the seconds keyword argument is now called delay (for those who passed the delay time as a keyword argument)

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 1 guest