Add docstrings to Backoff class's methods.
This commit is contained in:
parent
60abcbc8e3
commit
12a0c81819
1 changed files with 16 additions and 3 deletions
|
@ -26,22 +26,35 @@ class Backoff:
|
||||||
self.max = max
|
self.max = max
|
||||||
|
|
||||||
def current(self):
|
def current(self):
|
||||||
|
'''
|
||||||
|
Return the current backoff value without advancing.
|
||||||
|
'''
|
||||||
y = self._calc()
|
y = self._calc()
|
||||||
if self.max is not None:
|
if self.max is not None:
|
||||||
y = min(y, self.max)
|
y = min(y, self.max)
|
||||||
return y
|
return y
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
|
'''
|
||||||
|
Return the current backoff value, then advance x.
|
||||||
|
'''
|
||||||
y = self.current()
|
y = self.current()
|
||||||
self.x += 1
|
self.x += 1
|
||||||
return y
|
return y
|
||||||
|
|
||||||
def rewind(self, steps):
|
|
||||||
self.x = max(0, self.x - steps)
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
'''
|
||||||
|
Reset x to 0.
|
||||||
|
'''
|
||||||
self.x = 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):
|
class Exponential(Backoff):
|
||||||
|
|
Loading…
Reference in a new issue