]> kaliko git repositories - python-musicpdaio.git/commitdiff
Switch to async/await
authorkaliko <kaliko@azylum.org>
Tue, 6 Nov 2018 13:24:17 +0000 (14:24 +0100)
committerkaliko <kaliko@azylum.org>
Tue, 6 Nov 2018 13:24:17 +0000 (14:24 +0100)
musicpdaio.py

index 4339f72a7ecb023c7b2d296a315bfd92856bab5f..5e2c480bc991635a3da716496c547755ebb219f7 100644 (file)
@@ -60,6 +60,7 @@ class Response:
                 ' '.join(self.resp.split('\n')[:2]),
                 self.version)
 
+
 class MPDProto(asyncio.Protocol):
     def __init__(self, future, payload):
         logging.debug('payload: "%s"', payload)
@@ -135,14 +136,13 @@ class MPDClient:
                                      (self.__class__.__name__, attr))
         return lambda *args: wrapper(command, args)
 
-    @asyncio.coroutine
-    def _connect(self, proto):
+    async def _connect(self, proto):
         # coroutine allowing Exception handling
         # src: http://comments.gmane.org/gmane.comp.python.tulip/1401
         try:
-            yield from self._evloop.create_connection(lambda: proto,
-                    host=self._host,
-                    port=self._port)
+            await self._evloop.create_connection(lambda: proto,
+                                                 host=self._host,
+                                                 port=self._port)
         except Exception as err:
             proto.future.set_exception(ConnectionError(err))
 
@@ -169,8 +169,8 @@ class MPDClient:
         """Run event loop gathering tasks from self.futures
         """
         if self.futures:
-           self._evloop.run_until_complete(asyncio.gather(*self.futures))
-           self.futures = []
+            self._evloop.run_until_complete(asyncio.gather(*self.futures))
+            self.futures = []
         else:
             logging.info('No task found in queue, need to set self.asio?')