From 2fdd834caf6fbb6e1885cf043c9cfdbdeae88ed1 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Thu, 2 Jan 2020 22:08:26 +0900 Subject: [PATCH] Extract method _check_pause() --- pytchat/core_async/livechat.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index cc1ab46..7b69b4d 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -149,15 +149,7 @@ class LiveChatAsync: try: async with aiohttp.ClientSession() as session: while(continuation and self._is_alive): - if self._pauser.empty(): - '''pause''' - await self._pauser.get() - '''resume: - prohibit from blocking by putting None into _pauser. - ''' - self._pauser.put_nowait(None) - if self._parser.mode == 'LIVE': - continuation = liveparam.getparam(self.video_id,3) + continuation = await self._check_pause(continuation) contents = await self._get_contents( continuation, session, headers) metadata, chatdata = self._parser.parse(contents) @@ -190,6 +182,18 @@ class LiveChatAsync: logger.debug(f"[{self.video_id}]チャット取得を終了しました。") self.terminate() + async def _check_pause(self, continuation): + if self._pauser.empty(): + '''pause''' + await self._pauser.get() + '''resume: + prohibit from blocking by putting None into _pauser. + ''' + self._pauser.put_nowait(None) + if self._parser.mode == 'LIVE': + continuation = liveparam.getparam(self.video_id,3) + return continuation + async def _get_contents(self, continuation, session, headers): '''Get 'contents' dict from livechat json. If contents is None at first fetching,