Make use of the async_generator module

This commit is contained in:
Lonami Exo
2018-06-10 21:50:28 +02:00
parent 15ef302428
commit 8be6adeab4
3 changed files with 21 additions and 11 deletions

View File

@@ -1,5 +1,7 @@
from collections import UserList
from async_generator import async_generator, yield_
from .users import UserMethods
from .. import utils
from ..tl import types, functions
@@ -9,6 +11,7 @@ class ChatMethods(UserMethods):
# region Public methods
@async_generator
async def iter_participants(
self, entity, limit=None, search='',
filter=None, aggressive=False, _total=None):
@@ -130,7 +133,7 @@ class ChatMethods(UserMethods):
seen.add(participant.user_id)
user = users[participant.user_id]
user.participant = participant
yield user
await yield_(user)
if len(seen) >= limit:
return
@@ -159,7 +162,7 @@ class ChatMethods(UserMethods):
else:
user = users[participant.user_id]
user.participant = participant
yield user
await yield_(user)
else:
if _total:
_total[0] = 1
@@ -167,7 +170,7 @@ class ChatMethods(UserMethods):
user = await self.get_entity(entity)
if filter_entity(user):
user.participant = None
yield user
await yield_(user)
async def get_participants(self, *args, **kwargs):
"""