@@ -517,7 +517,7 @@ def __init__(
517
517
# TODO reconnection logic
518
518
self .ws_url = ws_url
519
519
self .ws : Optional ["ClientConnection" ] = None
520
- self .max_subscriptions = max_subscriptions
520
+ self .max_subscriptions = asyncio . Semaphore ( max_subscriptions )
521
521
self .max_connections = max_connections
522
522
self .shutdown_timer = shutdown_timer
523
523
self ._received = {}
@@ -632,6 +632,7 @@ async def send(self, payload: dict) -> int:
632
632
# async with self._lock:
633
633
original_id = get_next_id ()
634
634
# self._open_subscriptions += 1
635
+ await self .max_subscriptions .acquire ()
635
636
try :
636
637
await self .ws .send (json .dumps ({** payload , ** {"id" : original_id }}))
637
638
return original_id
@@ -650,7 +651,9 @@ async def retrieve(self, item_id: int) -> Optional[dict]:
650
651
retrieved item
651
652
"""
652
653
try :
653
- return self ._received .pop (item_id )
654
+ item = self ._received .pop (item_id )
655
+ self .max_subscriptions .release ()
656
+ return item
654
657
except KeyError :
655
658
await asyncio .sleep (0.001 )
656
659
return None
@@ -877,7 +880,7 @@ async def decode_scale(
877
880
scale_bytes : bytes ,
878
881
_attempt = 1 ,
879
882
_retries = 3 ,
880
- return_scale_obj = False ,
883
+ return_scale_obj : bool = False ,
881
884
) -> Union [ScaleObj , Any ]:
882
885
"""
883
886
Helper function to decode arbitrary SCALE-bytes (e.g. 0x02000000) according to given RUST type_string
@@ -2764,13 +2767,13 @@ async def runtime_call(
2764
2767
Returns:
2765
2768
ScaleType from the runtime call
2766
2769
"""
2767
- await self .init_runtime (block_hash = block_hash )
2770
+ runtime = await self .init_runtime (block_hash = block_hash )
2768
2771
2769
2772
if params is None :
2770
2773
params = {}
2771
2774
2772
2775
try :
2773
- metadata_v15_value = self . runtime .metadata_v15 .value ()
2776
+ metadata_v15_value = runtime .metadata_v15 .value ()
2774
2777
2775
2778
apis = {entry ["name" ]: entry for entry in metadata_v15_value ["apis" ]}
2776
2779
api_entry = apis [api ]
0 commit comments