Add a lock for resolving events

This commit is contained in:
Lonami Exo 2018-06-15 10:11:22 +02:00
parent df15ee421c
commit 31c94ec184
2 changed files with 9 additions and 3 deletions

View File

@ -196,6 +196,7 @@ class TelegramBaseClient(abc.ABC):
# Some further state for subclasses
self._event_builders = []
self._events_pending_resolve = []
self._event_resolve_lock = asyncio.Lock()
# Default parse mode
self._parse_mode = markdown

View File

@ -159,9 +159,14 @@ class UpdateMethods(UserMethods):
async def _dispatch_update(self, update):
if self._events_pending_resolve:
# TODO Add lock not to resolve them twice
for event in self._events_pending_resolve:
await event.resolve(self)
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:
await event.resolve(self)
self._events_pending_resolve.clear()
for builder, callback in self._event_builders: