Skip to content

Commit

Permalink
Remove infinite Deadline support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Jan 4, 2025
1 parent 746adcb commit 920b2eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
21 changes: 2 additions & 19 deletions aio_request/deadline.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import time
from typing import Any

MIN_TIMEOUT_SECONDS = 0.001
INFINITE_TIMEOUT_SECONDS = 0


class Deadline:
@staticmethod
Expand All @@ -18,21 +15,12 @@ def __init__(self, started_at: float, seconds: float):

@property
def timeout(self) -> float:
if self.__started_at == 0:
return INFINITE_TIMEOUT_SECONDS

remaining = self.__seconds - self.__get_elapsed()
return remaining if remaining > MIN_TIMEOUT_SECONDS else MIN_TIMEOUT_SECONDS
return remaining if remaining > 0 else 0

@property
def expired(self) -> bool:
if self.__started_at == 0:
return False
return self.__seconds - self.__get_elapsed() <= MIN_TIMEOUT_SECONDS

@property
def infinite(self) -> bool:
return self.__started_at == 0
return self.__seconds - self.__get_elapsed() <= 0

def __truediv__(self, divisor: Any) -> "Deadline":
if not isinstance(divisor, (int, float)):
Expand All @@ -44,17 +32,12 @@ def __truediv__(self, divisor: Any) -> "Deadline":
if divisor < 0:
raise ValueError("division by negative number")

if self.infinite:
return self

return Deadline.from_timeout(self.timeout / divisor)

def __float__(self) -> float:
return self.timeout

def __repr__(self) -> str:
if self.infinite:
return "<Deadline [infinite]>"
if self.expired:
return "<Deadline [expired]>"
return f"<Deadline [timeout={self.timeout}]>"
Expand Down
3 changes: 0 additions & 3 deletions aio_request/deadline_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def split_deadline_between_attempts() -> DeadlineProvider:
"""

def __provider(deadline: Deadline, attempt: int, attempts_count: int) -> Deadline:
if deadline.infinite:
return deadline

if deadline.expired:
return deadline

Expand Down

0 comments on commit 920b2eb

Please sign in to comment.