Skip to content

Commit

Permalink
(fix) Introduce timeoutheight_sync_interval parameter for client
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelInjective committed Nov 21, 2024
1 parent cd67089 commit 411fb10
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
network: Network,
insecure: Optional[bool] = None,
credentials=None,
timeoutheight_sync_interval: Optional[int] = DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL,
):
# the `insecure` parameter is ignored and will be deprecated soon. The value is taken directly from `network`
if insecure is not None:
Expand Down Expand Up @@ -154,6 +155,7 @@ def __init__(
self.chain_stream_stub = stream_rpc_grpc.StreamStub(channel=self.chain_stream_channel)

self._timeout_height_sync_task = None
self._timeoutheight_sync_interval = timeoutheight_sync_interval
self._initialize_timeout_height_sync_task()

self._tokens_and_markets_initialization_lock = asyncio.Lock()
Expand Down Expand Up @@ -3450,13 +3452,14 @@ async def _tokens_from_official_lists(
return tokens_by_symbol, tokens_by_denom

def _initialize_timeout_height_sync_task(self):
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.get_event_loop().create_task(self._timeout_height_sync_process())
if self._timeoutheight_sync_interval is not None:
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.get_event_loop().create_task(self._timeout_height_sync_process())

async def _timeout_height_sync_process(self):
while True:
await self.sync_timeout_height()
await asyncio.sleep(DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL)
await asyncio.sleep(self._timeoutheight_sync_interval)

def _cancel_timeout_height_sync_task(self):
if self._timeout_height_sync_task is not None:
Expand Down

0 comments on commit 411fb10

Please sign in to comment.