@@ -516,7 +516,7 @@ def __init__(
516
516
# TODO reconnection logic
517
517
self .ws_url = ws_url
518
518
self .ws : Optional ["ClientConnection" ] = None
519
- self .max_subscriptions = max_subscriptions
519
+ self .max_subscriptions = asyncio . Semaphore ( max_subscriptions )
520
520
self .max_connections = max_connections
521
521
self .shutdown_timer = shutdown_timer
522
522
self ._received = {}
@@ -631,6 +631,7 @@ async def send(self, payload: dict) -> int:
631
631
# async with self._lock:
632
632
original_id = get_next_id ()
633
633
# self._open_subscriptions += 1
634
+ await self .max_subscriptions .acquire ()
634
635
try :
635
636
await self .ws .send (json .dumps ({** payload , ** {"id" : original_id }}))
636
637
return original_id
@@ -649,7 +650,9 @@ async def retrieve(self, item_id: int) -> Optional[dict]:
649
650
retrieved item
650
651
"""
651
652
try :
652
- return self ._received .pop (item_id )
653
+ item = self ._received .pop (item_id )
654
+ self .max_subscriptions .release ()
655
+ return item
653
656
except KeyError :
654
657
await asyncio .sleep (0.001 )
655
658
return None
@@ -876,7 +879,7 @@ async def decode_scale(
876
879
scale_bytes : bytes ,
877
880
_attempt = 1 ,
878
881
_retries = 3 ,
879
- return_scale_obj = False ,
882
+ return_scale_obj : bool = False ,
880
883
) -> Union [ScaleObj , Any ]:
881
884
"""
882
885
Helper function to decode arbitrary SCALE-bytes (e.g. 0x02000000) according to given RUST type_string
@@ -2528,13 +2531,13 @@ async def runtime_call(
2528
2531
Returns:
2529
2532
ScaleType from the runtime call
2530
2533
"""
2531
- await self .init_runtime (block_hash = block_hash )
2534
+ runtime = await self .init_runtime (block_hash = block_hash )
2532
2535
2533
2536
if params is None :
2534
2537
params = {}
2535
2538
2536
2539
try :
2537
- metadata_v15_value = self . runtime .metadata_v15 .value ()
2540
+ metadata_v15_value = runtime .metadata_v15 .value ()
2538
2541
2539
2542
apis = {entry ["name" ]: entry for entry in metadata_v15_value ["apis" ]}
2540
2543
api_entry = apis [api ]
0 commit comments