@@ -516,7 +516,7 @@ def __init__(
516516 # TODO reconnection logic
517517 self .ws_url = ws_url
518518 self .ws : Optional ["ClientConnection" ] = None
519- self .max_subscriptions = max_subscriptions
519+ self .max_subscriptions = asyncio . Semaphore ( max_subscriptions )
520520 self .max_connections = max_connections
521521 self .shutdown_timer = shutdown_timer
522522 self ._received = {}
@@ -631,6 +631,7 @@ async def send(self, payload: dict) -> int:
631631 # async with self._lock:
632632 original_id = get_next_id ()
633633 # self._open_subscriptions += 1
634+ await self .max_subscriptions .acquire ()
634635 try :
635636 await self .ws .send (json .dumps ({** payload , ** {"id" : original_id }}))
636637 return original_id
@@ -649,7 +650,9 @@ async def retrieve(self, item_id: int) -> Optional[dict]:
649650 retrieved item
650651 """
651652 try :
652- return self ._received .pop (item_id )
653+ item = self ._received .pop (item_id )
654+ self .max_subscriptions .release ()
655+ return item
653656 except KeyError :
654657 await asyncio .sleep (0.001 )
655658 return None
@@ -876,7 +879,7 @@ async def decode_scale(
876879 scale_bytes : bytes ,
877880 _attempt = 1 ,
878881 _retries = 3 ,
879- return_scale_obj = False ,
882+ return_scale_obj : bool = False ,
880883 ) -> Union [ScaleObj , Any ]:
881884 """
882885 Helper function to decode arbitrary SCALE-bytes (e.g. 0x02000000) according to given RUST type_string
@@ -2528,13 +2531,13 @@ async def runtime_call(
25282531 Returns:
25292532 ScaleType from the runtime call
25302533 """
2531- await self .init_runtime (block_hash = block_hash )
2534+ runtime = await self .init_runtime (block_hash = block_hash )
25322535
25332536 if params is None :
25342537 params = {}
25352538
25362539 try :
2537- metadata_v15_value = self . runtime .metadata_v15 .value ()
2540+ metadata_v15_value = runtime .metadata_v15 .value ()
25382541
25392542 apis = {entry ["name" ]: entry for entry in metadata_v15_value ["apis" ]}
25402543 api_entry = apis [api ]
0 commit comments