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,14 +1,17 @@
import itertools
from collections import UserList
from async_generator import async_generator, yield_
from .users import UserMethods
from ..tl import types, functions, custom
from .. import utils
from ..tl import types, functions, custom
class DialogMethods(UserMethods):
# region Public methods
@async_generator
async def iter_dialogs(
self, limit=None, offset_date=None, offset_id=0,
offset_peer=types.InputPeerEmpty(), _total=None):
@@ -80,7 +83,7 @@ class DialogMethods(UserMethods):
peer_id = utils.get_peer_id(d.peer)
if peer_id not in seen:
seen.add(peer_id)
yield custom.Dialog(self, d, entities, messages)
await yield_(custom.Dialog(self, d, entities, messages))
if len(r.dialogs) < req.limit\
or not isinstance(r, types.messages.DialogsSlice):
@@ -115,7 +118,7 @@ class DialogMethods(UserMethods):
"""
r = await self(functions.messages.GetAllDraftsRequest())
for update in r.updates:
yield custom.Draft._from_update(self, update)
await yield_(custom.Draft._from_update(self, update))
async def get_drafts(self):
"""