File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 4444
4545import asyncio
4646import typing
47+ from collections .abc import Set
4748
4849from ._receiver import Receiver
4950
@@ -145,6 +146,13 @@ def unique_id(self) -> str:
145146 """The unique identifier of this instance."""
146147 return self ._unique_id
147148
149+ def keys (self ) -> Set [HashableT ]:
150+ """Return the set of keys for which values have been received.
151+
152+ If no key function is provided, this will return an empty set.
153+ """
154+ return self ._latest_value_by_key .keys ()
155+
148156 def get (self , key : HashableT | Sentinel = NO_KEY ) -> T_co :
149157 """Return the latest value that has been received.
150158
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ async def test_latest_value_cache() -> None:
4444
4545 assert cache .get () == 19
4646
47+ assert cache .keys () == set ()
48+
4749
4850@pytest .mark .integration
4951async def test_latest_value_cache_key () -> None :
@@ -59,6 +61,8 @@ async def test_latest_value_cache_key() -> None:
5961 with pytest .raises (ValueError , match = "No value received for key: 0" ):
6062 cache .get (0 )
6163
64+ assert cache .keys () == set ()
65+
6266 await sender .send ((5 , "a" ))
6367 await sender .send ((6 , "b" ))
6468 await sender .send ((5 , "c" ))
@@ -73,6 +77,8 @@ async def test_latest_value_cache_key() -> None:
7377 assert cache .get (5 ) == (5 , "c" )
7478 assert cache .get (6 ) == (6 , "b" )
7579
80+ assert cache .keys () == {5 , 6 }
81+
7682 with pytest .raises (ValueError , match = "No value received for key: 7" ):
7783 cache .get (7 )
7884
@@ -92,3 +98,5 @@ async def test_latest_value_cache_key() -> None:
9298 await asyncio .sleep (0 )
9399
94100 assert cache .get (6 ) == (6 , "g" )
101+
102+ assert cache .keys () == {5 , 6 , 12 }
You can’t perform that action at this time.
0 commit comments