Add docstrings to Backoff class's methods.

master
voussoir 2021-05-03 18:32:18 -07:00
parent 60abcbc8e3
commit 12a0c81819
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 16 additions and 3 deletions

View File

@ -26,22 +26,35 @@ class Backoff:
self.max = max
def current(self):
'''
Return the current backoff value without advancing.
'''
y = self._calc()
if self.max is not None:
y = min(y, self.max)
return y
def next(self):
'''
Return the current backoff value, then advance x.
'''
y = self.current()
self.x += 1
return y
def rewind(self, steps):
self.x = max(0, self.x - steps)
def reset(self):
'''
Reset x to 0.
'''
self.x = 0
def rewind(self, steps):
'''
Subtract this many steps from x, to ease up the backoff without
entirely resetting.
'''
self.x = max(0, self.x - steps)
####################################################################################################
class Exponential(Backoff):