Skip to content

Commit

Permalink
docs: 📝 Better documentation for latency properties (#2653)
Browse files Browse the repository at this point in the history
📝 Better documentation for latency methods
  • Loading branch information
Paillat-dev authored Nov 28, 2024
1 parent 1b2972b commit da90e33
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ def _handle_ready(self) -> None:

@property
def latency(self) -> float:
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds.
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no websocket
is present, this returns ``nan``, and if no heartbeat has been received yet, this returns ``float('inf')``.
This could be referred to as the Discord WebSocket protocol latency.
"""
Expand Down
4 changes: 3 additions & 1 deletion discord/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ async def received_message(self, msg, /):

@property
def latency(self) -> float:
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds."""
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no heartbeat
has been received yet this returns ``float('inf')``.
"""
heartbeat = self._keep_alive
return float("inf") if heartbeat is None else heartbeat.latency

Expand Down
4 changes: 3 additions & 1 deletion discord/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ async def connect(self) -> None:

@property
def latency(self) -> float:
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds for this shard."""
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds for this shard. If no heartbeat
has been received yet this returns ``float('inf')``.
"""
return self._parent.ws.latency

def is_ws_ratelimited(self) -> bool:
Expand Down

0 comments on commit da90e33

Please sign in to comment.