Make push_to_loop public.

master
blallo 2019-08-17 22:22:14 -03:00 committed by blallo
parent aba31919f5
commit 7d8a6c4075
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
1 changed files with 8 additions and 8 deletions

View File

@ -7,7 +7,7 @@ the Operator.
""" """
import asyncio import asyncio
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor, Executor
import functools import functools
import logging import logging
import typing as T import typing as T
@ -19,9 +19,9 @@ from bot_z.exceptions import OperationFailed
alog = logging.getLogger("asyncio") alog = logging.getLogger("asyncio")
async def _push_to_loop( async def push_to_loop(
loop: asyncio.AbstractEventLoop, loop: asyncio.AbstractEventLoop,
executor: ThreadPoolExecutor, executor: Executor,
func: T.Callable, func: T.Callable,
*args, *args,
**kwargs **kwargs
@ -52,7 +52,7 @@ class AsyncOperator(object):
async def login(self, username: str, password: str) -> None: async def login(self, username: str, password: str) -> None:
"""Perform the login. Raise if failing.""" """Perform the login. Raise if failing."""
alog.debug("Logging in [%s]", self.name) alog.debug("Logging in [%s]", self.name)
_ = await _push_to_loop( _ = await push_to_loop(
self.loop, self.executor, self.op.login, username, password self.loop, self.executor, self.op.login, username, password
) )
if not self.op.logged_in: if not self.op.logged_in:
@ -62,7 +62,7 @@ class AsyncOperator(object):
async def logout(self) -> None: async def logout(self) -> None:
"""Perform the logout. Raise if failing.""" """Perform the logout. Raise if failing."""
alog.debug("Logging out [%s]", self.name) alog.debug("Logging out [%s]", self.name)
_ = await _push_to_loop(self.loop, self.executor, self.op.logout) _ = await push_to_loop(self.loop, self.executor, self.op.logout)
if self.op.logged_in: if self.op.logged_in:
raise OperationFailed("Failed to logout.") raise OperationFailed("Failed to logout.")
alog.info("Logged out [%s]", self.name) alog.info("Logged out [%s]", self.name)
@ -70,7 +70,7 @@ class AsyncOperator(object):
async def checkin(self) -> None: async def checkin(self) -> None:
"""Perform the checkin. Raise if failing.""" """Perform the checkin. Raise if failing."""
alog.debug("Checking in [%s]", self.name) alog.debug("Checking in [%s]", self.name)
_ = await _push_to_loop(self.loop, self.executor, self.op.check_in) _ = await push_to_loop(self.loop, self.executor, self.op.check_in)
if not self.op.checked_in: if not self.op.checked_in:
raise OperationFailed("Failed to checkin.") raise OperationFailed("Failed to checkin.")
alog.info("Checked in [%s]", self.name) alog.info("Checked in [%s]", self.name)
@ -78,7 +78,7 @@ class AsyncOperator(object):
async def checkout(self) -> None: async def checkout(self) -> None:
"""Perform the checkout. Raise if failing.""" """Perform the checkout. Raise if failing."""
alog.debug("Checking out [%s]", self.name) alog.debug("Checking out [%s]", self.name)
_ = await _push_to_loop(self.loop, self.executor, self.op.check_out) _ = await push_to_loop(self.loop, self.executor, self.op.check_out)
if self.op.checked_in: if self.op.checked_in:
raise OperationFailed("Failed to checkout.") raise OperationFailed("Failed to checkout.")
alog.info("Checked out [%s]", self.name) alog.info("Checked out [%s]", self.name)
@ -89,7 +89,7 @@ class AsyncOperator(object):
The list may be empty. The list may be empty.
""" """
alog.debug("Retrieving the list of movements [%s]", self.name) alog.debug("Retrieving the list of movements [%s]", self.name)
res = await _push_to_loop(self.loop, self.executor, self.op.get_movements) res = await push_to_loop(self.loop, self.executor, self.op.get_movements)
alog.info("List of movements [%s]: %s", self.name, res) alog.info("List of movements [%s]: %s", self.name, res)
return res return res