mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-17 17:28:05 +00:00
fix: gracefully cancel blockhash updater task
This commit is contained in:
+9
-3
@@ -36,8 +36,7 @@ class SolanaClient:
|
|||||||
self._client = None
|
self._client = None
|
||||||
self._cached_blockhash: Hash | None = None
|
self._cached_blockhash: Hash | None = None
|
||||||
self._blockhash_lock = asyncio.Lock()
|
self._blockhash_lock = asyncio.Lock()
|
||||||
|
self._blockhash_updater_task = asyncio.create_task(self.start_blockhash_updater())
|
||||||
asyncio.create_task(self.start_blockhash_updater())
|
|
||||||
|
|
||||||
async def start_blockhash_updater(self, interval: float = 5.0):
|
async def start_blockhash_updater(self, interval: float = 5.0):
|
||||||
"""Start background task to update recent blockhash."""
|
"""Start background task to update recent blockhash."""
|
||||||
@@ -68,7 +67,14 @@ class SolanaClient:
|
|||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
"""Close the client connection if open."""
|
"""Close the client connection and stop the blockhash updater."""
|
||||||
|
if self._blockhash_updater_task:
|
||||||
|
self._blockhash_updater_task.cancel()
|
||||||
|
try:
|
||||||
|
await self._blockhash_updater_task
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
|
||||||
if self._client:
|
if self._client:
|
||||||
await self._client.close()
|
await self._client.close()
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|||||||
Reference in New Issue
Block a user