Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 📝 Better documentation for latency properties #2653

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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