[docs]classExponentialBackoff:""" Implementation of the exponential backoff algorithm. Parameters ---------- initial: The initial value for the exponential. multiplier: Value to multiply initial value. max_value: The maximum value of the exponential. Attributes ---------- current: :class:`float` The current value of the exponential. """__slots__=("current","_multiplier","_max","_initial","_total")def__init__(self,initial:float,multiplier:float,max_value:float)->None:self.current:float=0self._multiplier:float=multiplierself._max:float=max_valueself._total:float=0.0self._initial:float=initialdef__repr__(self)->str:returnf"<ExponentialBackoff(current={self.current}, next={self.next}, total={self.total})>"def__iter__(self)->Self:returnselfdef__next__(self)->float:ifself.current:self.current=self.nextself._total+=self.currentelse:self.current=self._initialreturnself.current@propertydefnext(self)->float:"""Next value of exponential."""returnmin(self._max,self.current*self._multiplier)@propertydeftotal(self)->float:"""Total value of exponential."""returnself._total
[docs]defreset(self)->None:"""Method to reset the exponential backoff."""self.current=0self._total=0.0