@@ -1292,10 +1292,11 @@ class TopologyClosedEvent(TopologyEvent):
12921292class _ServerHeartbeatEvent :
12931293 """Base class for server heartbeat events."""
12941294
1295- __slots__ = "__connection_id"
1295+ __slots__ = ( "__connection_id" , "__awaited" )
12961296
1297- def __init__ (self , connection_id : _Address ) -> None :
1297+ def __init__ (self , connection_id : _Address , awaited : bool = False ) -> None :
12981298 self .__connection_id = connection_id
1299+ self .__awaited = awaited
12991300
13001301 @property
13011302 def connection_id (self ) -> _Address :
@@ -1304,8 +1305,16 @@ def connection_id(self) -> _Address:
13041305 """
13051306 return self .__connection_id
13061307
1308+ @property
1309+ def awaited (self ) -> bool :
1310+ """Whether the heartbeat was issued as an awaitable hello command.
1311+
1312+ .. versionadded:: 4.6
1313+ """
1314+ return self .__awaited
1315+
13071316 def __repr__ (self ) -> str :
1308- return f"<{ self .__class__ .__name__ } { self .connection_id } >"
1317+ return f"<{ self .__class__ .__name__ } { self .connection_id } awaited: { self . awaited } >"
13091318
13101319
13111320class ServerHeartbeatStartedEvent (_ServerHeartbeatEvent ):
@@ -1323,15 +1332,14 @@ class ServerHeartbeatSucceededEvent(_ServerHeartbeatEvent):
13231332 .. versionadded:: 3.3
13241333 """
13251334
1326- __slots__ = ("__duration" , "__reply" , "__awaited" )
1335+ __slots__ = ("__duration" , "__reply" )
13271336
13281337 def __init__ (
13291338 self , duration : float , reply : Hello , connection_id : _Address , awaited : bool = False
13301339 ) -> None :
1331- super ().__init__ (connection_id )
1340+ super ().__init__ (connection_id , awaited )
13321341 self .__duration = duration
13331342 self .__reply = reply
1334- self .__awaited = awaited
13351343
13361344 @property
13371345 def duration (self ) -> float :
@@ -1350,8 +1358,10 @@ def awaited(self) -> bool:
13501358 If true, then :meth:`duration` reflects the sum of the round trip time
13511359 to the server and the time that the server waited before sending a
13521360 response.
1361+
1362+ .. versionadded:: 3.11
13531363 """
1354- return self . __awaited
1364+ return super (). awaited
13551365
13561366 def __repr__ (self ) -> str :
13571367 return "<{} {} duration: {}, awaited: {}, reply: {}>" .format (
@@ -1370,15 +1380,14 @@ class ServerHeartbeatFailedEvent(_ServerHeartbeatEvent):
13701380 .. versionadded:: 3.3
13711381 """
13721382
1373- __slots__ = ("__duration" , "__reply" , "__awaited" )
1383+ __slots__ = ("__duration" , "__reply" )
13741384
13751385 def __init__ (
13761386 self , duration : float , reply : Exception , connection_id : _Address , awaited : bool = False
13771387 ) -> None :
1378- super ().__init__ (connection_id )
1388+ super ().__init__ (connection_id , awaited )
13791389 self .__duration = duration
13801390 self .__reply = reply
1381- self .__awaited = awaited
13821391
13831392 @property
13841393 def duration (self ) -> float :
@@ -1397,8 +1406,10 @@ def awaited(self) -> bool:
13971406 If true, then :meth:`duration` reflects the sum of the round trip time
13981407 to the server and the time that the server waited before sending a
13991408 response.
1409+
1410+ .. versionadded:: 3.11
14001411 """
1401- return self . __awaited
1412+ return super (). awaited
14021413
14031414 def __repr__ (self ) -> str :
14041415 return "<{} {} duration: {}, awaited: {}, reply: {!r}>" .format (
@@ -1602,14 +1613,15 @@ def publish_command_failure(
16021613 except Exception :
16031614 _handle_exception ()
16041615
1605- def publish_server_heartbeat_started (self , connection_id : _Address ) -> None :
1616+ def publish_server_heartbeat_started (self , connection_id : _Address , awaited : bool ) -> None :
16061617 """Publish a ServerHeartbeatStartedEvent to all server heartbeat
16071618 listeners.
16081619
16091620 :Parameters:
16101621 - `connection_id`: The address (host, port) pair of the connection.
1622+ - `awaited`: True if this heartbeat is part of an awaitable hello command.
16111623 """
1612- event = ServerHeartbeatStartedEvent (connection_id )
1624+ event = ServerHeartbeatStartedEvent (connection_id , awaited )
16131625 for subscriber in self .__server_heartbeat_listeners :
16141626 try :
16151627 subscriber .started (event )
0 commit comments