mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 19:00:21 +03:00
Add a lock for resolving events
This commit is contained in:
parent
df15ee421c
commit
31c94ec184
|
@ -196,6 +196,7 @@ class TelegramBaseClient(abc.ABC):
|
||||||
# Some further state for subclasses
|
# Some further state for subclasses
|
||||||
self._event_builders = []
|
self._event_builders = []
|
||||||
self._events_pending_resolve = []
|
self._events_pending_resolve = []
|
||||||
|
self._event_resolve_lock = asyncio.Lock()
|
||||||
|
|
||||||
# Default parse mode
|
# Default parse mode
|
||||||
self._parse_mode = markdown
|
self._parse_mode = markdown
|
||||||
|
|
|
@ -159,9 +159,14 @@ class UpdateMethods(UserMethods):
|
||||||
|
|
||||||
async def _dispatch_update(self, update):
|
async def _dispatch_update(self, update):
|
||||||
if self._events_pending_resolve:
|
if self._events_pending_resolve:
|
||||||
# TODO Add lock not to resolve them twice
|
if self._event_resolve_lock.locked():
|
||||||
|
async with self._event_resolve_lock:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
async with self._event_resolve_lock:
|
||||||
for event in self._events_pending_resolve:
|
for event in self._events_pending_resolve:
|
||||||
await event.resolve(self)
|
await event.resolve(self)
|
||||||
|
|
||||||
self._events_pending_resolve.clear()
|
self._events_pending_resolve.clear()
|
||||||
|
|
||||||
for builder, callback in self._event_builders:
|
for builder, callback in self._event_builders:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user